Scripts: varbond.py

File varbond.py, 779 bytes (added by pett, 12 years ago)
Line 
1noBond = 3.5
2fullBond = 2.0
3resIDs = ["57.A", "68.A"]
4atomNames = ["SG", "N"]
5
6from chimera import openModels, Molecule, Bond
7bondRepr = Bond.Stick
8fullRadius = 0.2
9
10atoms = []
11allAtoms = openModels.list(modelTypes=[Molecule])[0].atoms
12for resID, atomName in zip(resIDs, atomNames):
13 for a in allAtoms:
14 if str(a.residue.id) == resID:
15 atoms.append(a.residue.atomsMap[atomName][0])
16 break
17
18a1, a2 = atoms
19dist = a1.coord().distance(a2.coord())
20
21if dist >= noBond:
22 if a1 in a2.neighbors:
23 a1.molecule.deleteBond(a1.bondsMap[a2])
24else:
25 if a1 not in a2.neighbors:
26 b = a1.molecule.newBond(a1, a2)
27 b.drawMode = bondRepr
28 else:
29 b = a1.bondsMap[a2]
30 if dist <= fullBond:
31 b.radius = fullRadius
32 else:
33 b.radius = fullRadius * (1.0 - (dist-fullBond) / (noBond-fullBond))