From 7bf2bd12d7f9c621ba3721f3f324a7f66a0b4874 Mon Sep 17 00:00:00 2001 From: Lee-Ping Wang Date: Sat, 10 Nov 2018 18:09:06 -0800 Subject: [PATCH] Add unit tests for measure_distances, measure_angles, measure_dihedrals --- src/molecule.py | 3 ++- test/test_molecule.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/molecule.py b/src/molecule.py index d7f74db54..ba6edb11f 100644 --- a/src/molecule.py +++ b/src/molecule.py @@ -3554,7 +3554,8 @@ def read_pdb(self, fnm, **kwargs): conect_B_list.append(int(line_rest[:5]) - 1) line_rest = line_rest[5:] for conect_B in conect_B_list: - bonds.append([conect_A, conect_B]) + bond = (min((conect_A, conect_B)), max((conect_A, conect_B))) + bonds.append(bond) Answer={"xyzs":XYZList, "chain":list(ChainID), "altloc":list(AltLoc), "icode":list(ICode), "atomname":[str(i) for i in AtomNames], "resid":list(ResidueID), "resname":list(ResidueNames), diff --git a/test/test_molecule.py b/test/test_molecule.py index 4ee08c386..2c866d07e 100644 --- a/test/test_molecule.py +++ b/test/test_molecule.py @@ -40,6 +40,30 @@ def test_xyz_conversion(self): msg = "\nConversion from pdb to xyz yields different xyz coordinates\npdb:\n%s\n\ngro:\n%s\n" %\ (str(self.molecule.Data['xyzs'][0]), str(molecule1.Data['xyzs'][0]))) + def test_measure_distances(self): + """Check measure distance functions""" + result = np.array(self.molecule.measure_distances(1701, 1706)) + EXPECTED_DISTANCE_RESULTS = np.array([1.80]) + self.assertNdArrayEqual(EXPECTED_DISTANCE_RESULTS,result,delta=0.01, + msg="\nMeasured distance has changed from previously calculated values.\n" + "If this seems reasonable, update EXPECTED_DISTANCE_RESULTS in test_molecule.py with these values") + + def test_measure_angles(self): + """Check measure angle functions""" + result = np.array(self.molecule.measure_angles(1771, 1769, 1772)) + EXPECTED_ANGLE_RESULTS = np.array([114.11]) + self.assertNdArrayEqual(EXPECTED_ANGLE_RESULTS,result,delta=0.01, + msg="\nMeasured angle has changed from previously calculated values.\n" + "If this seems reasonable, update EXPECTED_ANGLE_RESULTS in test_molecule.py with these values") + + def test_measure_dihedrals(self): + """Check measure dihedral functions""" + result = np.array(self.molecule.measure_dihedrals(1709, 1706, 1701, 1702)) + EXPECTED_DIHEDRAL_RESULTS = np.array([176.54]) + self.assertNdArrayEqual(EXPECTED_DIHEDRAL_RESULTS,result,delta=0.01, + msg="\nMeasured dihedral angle has changed from previously calculated values.\n" + "If this seems reasonable, update EXPECTED_DIHEDRAL_RESULTS in test_molecule.py with these values") + def test_gro_conversion(self): """Check molecule conversion from pdb to gro format""" self.logger.debug("\nCreating gro file from pdb... ") @@ -106,6 +130,14 @@ def setUp(self): self.skipTest("Input pdb file test/files/%s doesn't exist" % self.source) except: self.fail("\nUnable to open gro file") + + def test_measure_dihedrals(self): + """Check measure dihedral functions""" + result = np.array(self.molecule.measure_dihedrals(1131, 1112, 1113, 1114)) + EXPECTED_DIHEDRAL_RESULTS = np.array([-157.223]) + self.assertNdArrayEqual(EXPECTED_DIHEDRAL_RESULTS,result,delta=0.001, + msg="\nMeasured dihedral angle has changed from previously calculated values.\n" + "If this seems reasonable, update EXPECTED_DIHEDRAL_RESULTS in test_molecule.py with these values") def test_lipid_molecules(self): """Check for the correct number of molecules in a rectangular cell with broken molecules"""