Let's start with the following basic depiction. Note that information on the SVG output options (e.g. -xC) is available in the docs or via "obabel -H svg", and that you can use the mouse to zoom in, etc.
obabel dataset.sdf -O output1.svg -xC
obabel dataset.sdf -O output1.svg -xC
import pybel | |
ob = pybel.ob | |
import numpy as np | |
def getfrag(mol, startid, ans): | |
# Get the disconnected fragment starting at startid | |
ans.append(startid) | |
for nbr in pybel.ob.OBAtomAtomIter(mol.GetAtom(startid)): | |
if nbr.GetIdx() not in ans: | |
getfrag(mol, nbr.GetIdx(), ans) | |
return ans | |
def t(v): # Convert vector3 to np.array | |
return np.array([v.GetX(), v.GetY(), v.GetZ()]) | |
def u(ar): # Convert np.array to vector3 | |
return ob.vector3(float(ar[0]), float(ar[1]), float(ar[2])) | |
def m(mat): # Convert matrix3x3 to np.array | |
ans = np.zeros((3,3), "d") | |
for i in range(3): | |
for j in range(3): | |
ans[i,j] = mat.Get(i, j) | |
return ans | |
if __name__ == "__main__": | |
mol = pybel.readfile("out", "CloseToTS.out").next().OBMol | |
# Split off the ligand | |
bond = mol.GetBond(mol.GetAtom(12), mol.GetAtom(27)) | |
mol.DeleteBond(bond) | |
# Get the indices of atoms in the ligand | |
fragment = getfrag(mol, 12, []) | |
# Plane composed of Points pqr | |
p = t(mol.GetAtom(12).GetVector()) | |
q = t(mol.GetAtom(50).GetVector()) | |
r = t(mol.GetAtom(51).GetVector()) | |
# Normal to plane pqr | |
planenormal = u(np.cross(p-q, p-r)) | |
# Get transformation matrix | |
matrix = ob.matrix3x3() | |
matrix.PlaneReflection(planenormal) | |
mmat = m(matrix) | |
# Apply the transformation | |
for atom in fragment: | |
vec = t(mol.GetAtom(atom).GetVector()) | |
vec = np.dot(vec, mmat) | |
mol.GetAtom(atom).SetVector(u(vec)) | |
# Add back the ligand bond | |
mol.AddBond(12, 27, 1) | |
pybel.Molecule(mol).write("sdf", "tmp.sdf", overwrite=True) |
"A real Page-Downer of a PDF. I was gripped from the Introduction right through to the Conclusion."
- Reviewer 1
"8 out of 10. A story of great entertainment in the field."
- Reviewer 2
"P2, paragraph 3: Several misspellings. In the future, are there no spell checkers?"
- Reviewer 3
"Rattles along at a rollicking pace. And that's just the abstract!"
- Reviewer 1
"I laughed. I cried. Then I read the article."
- Reviewer 2
"Publish with minor revisions to add tension."
- Reviewer 3