Distance between atoms using Python

Hi Ed, Attached is some Python code for controlling ligand display based on distance between two atoms. Tom Edward Brignole wrote:
Tom,
Thanks again for your help with that atom display. Got another MDtrajectory issue for you. I've got a ligand in each of 10 domains in the structure and I only want to display the ligands in the frames that have less than a certain distance between a particular atom in the ligand and a particular atom in a neighboring domain.
The distance command won't work for me because all it does is add a distance to the distance dialog when I need it as a variable in the script to evaluate with "if distance < 10: display atomspecs"
Sorry to keep bugging you with these things but I assure you it isn't without trying for several hours to no avail before finally resorting to asking.
Ed
def atom_distance(spec1, spec2): from chimera.specifier import evalSpec atom1 = evalSpec(spec1).atoms()[0] atom2 = evalSpec(spec2).atoms()[0] d = atom1.xformCoord().distance(atom2.xformCoord()) return d from chimera import runCommand if atom_distance('#0:15.B@C4', '#0:7.A@N3') >= 10: runCommand('display #0:SPM') else: runCommand('~display #0:SPM')
participants (1)
-
Tom Goddard