def GetBondGraph(mol): """Build graph of which atoms are covalently bonded and bond lengths. Search all atom pairs to find those within a threshold of the sum of the interatomic covalent radii. Append those found to the bond graph dictionary of each Atom object within the Molecule object. First atomic index is the array index. Second atomic index is a dictionary key. The value is the bond length [Angstrom] of the bond. Args: mol (mmlib.molecule.Molecule): Molecule object with Atom objects with geometry and mm parameter data. """ mol.bond_graph = [{} for i in range(mol.n_atoms)] bond_thresh = const.BONDTHRESHOLD for i in range(mol.n_atoms): at1 = mol.atoms[i] for j in range(i + 1, mol.n_atoms): at2 = mol.atoms[j] thresh = bond_thresh * (at1.covrad + at2.covrad) r2_12 = geomcalc.GetR2ij(at1.coords, at2.coords) if r2_12 < thresh**2: r_12 = math.sqrt(r2_12) mol.bond_graph[i][j] = r_12 mol.bond_graph[j][i] = r_12
def GetBondGraph(atoms): """Build graph of which atoms are covalently bonded and bond lengths. Search all atom pairs to find those within a threshold of the sum of the interatomic covalent radii. Append those found to the bond graph dictionary of each Atom object within the Molecule object. First atomic index is the array index. Second atomic index is a dictionary key. The value is the bond length [Angstrom] of the bond. Args: atoms (mmlib.molecule.Atom*): Array of Atom objects with coordinate and MM parameter data. Returns: bond_graph (int:(int:float)): Dictionary of bond connectivity. """ bond_graph = {i: {} for i in range(len(atoms))} for i, j in itertools.combinations(range(len(atoms)), 2): at1, at2 = atoms[i], atoms[j] threshold = const.BONDTHRESHOLD * (at1.covrad + at2.covrad) r2_12 = geomcalc.GetR2ij(at1.coords, at2.coords) if r2_12 < threshold**2: r_12 = math.sqrt(r2_12) bond_graph[i][j] = bond_graph[j][i] = r_12 return bond_graph
def testUnitLength(self): """Asserts unit value for points one distance unit apart.""" params = ORIGIN, NEGATIVE_UNIT_X self.assertAlmostEqual(geomcalc.GetR2ij(*params), 1.0)
def testSamePoint(self): """Asserts zero distance between identical points.""" params = ARBITRARY_XYZ1, ARBITRARY_XYZ1 self.assertAlmostEqual(geomcalc.GetR2ij(*params), 0.0)
def testReflexive(self): """Asserts same value for inverted order of inputs.""" params = ARBITRARY_XYZ2, ARBITRARY_XYZ1 self.assertAlmostEqual(geomcalc.GetR2ij(*params), 148.0921993)
def testArbitrary(self): """Asserts correct value for arbitrary points in 3d space.""" params = ARBITRARY_XYZ1, ARBITRARY_XYZ2 self.assertAlmostEqual(geomcalc.GetR2ij(*params), 148.0921993)
def testOnAxisZ(self): """Asserts correct value for points separated along z-axis.""" params = POSITIVE_ARBITRARY_Z, NEGATIVE_ARBITRARY_Z self.assertAlmostEqual(geomcalc.GetR2ij(*params), 159.3847166)
def testOnAxisY(self): """Asserts correct value for points separated along y-axis.""" params = NEGATIVE_ARBITRARY_Y, POSITIVE_ARBITRARY_Y self.assertAlmostEqual(geomcalc.GetR2ij(*params), 149.8505274)
def testOnAxisX(self): """Asserts correct value for points separated along x-axis.""" params = POSITIVE_ARBITRARY_X, NEGATIVE_ARBITRARY_X self.assertAlmostEqual(geomcalc.GetR2ij(*params), 151.5346474)