A script to create an atom C at a point some distance d from a pair of atoms (A, B), along the line of the bond A-B. The main function takes a modelName (usually, the name of the file loaded, like "1pqr" or "peptide"), a distance, and some parameters to identify the atoms A, B.
Use like:
createAtomAlongBond("gly", 3, 23, "H", 23, "N", "O")
.
<source lang="python">
import cmd
from chempy import models, cpv
"""
Create an atom at a distance 'distance' along the bond between atomA and atomB
"""
def createAtomAlongBond(modelName, distance, resiA, atomNameA, resiB, atomNameB, atomNameC):
model = cmd.get_model(modelName)
p1 = getAtomCoords(model, str(resiA), atomNameA)
p2 = getAtomCoords(model, str(resiB), atomNameB)
if p1 is None:
print "atom not found!", modelName, resiA, atomNameA
elif p2 is None:
print "atom not found!", modelName, resiB, atomNameB
else:
p3 = calculateNewPoint(p1, p2, distance)
# the details of the new atom
atomDetails = {}
..→