diff --git a/data/bonds.json b/data/bonds.json index 9680a6ee6772e53ac91bd02fb3496fda0157a8c3..60629a77e2bf6225c0d3a2e2fa9ac7cdd8d8f152 100644 --- a/data/bonds.json +++ b/data/bonds.json @@ -36,15 +36,19 @@ "sugar-dih-30pc-2": "fourier 2 0.75 3 0 -0.10 1 120", "sugar-dih-80pc-1": "fourier 2 0.75 3 0 -0.32 1 -120", "sugar-dih-80pc-2": "fourier 2 0.75 3 0 -0.32 1 120", - "sugar-glyc-d13": "charmm -0.1801345 1 -123.0662189 0.0", - "sugar-glyc-d14": "charmm -0.8522 1 -146.907595 0.0", - "sugar-glyc-d16": "charmm 0.4714055 1 0.8067885 0.0", - "sugar-glyc-d2a34": "charmm -0.819724 1 -65.408620 0.0", - "sugar-glyc-d2a6": "charmm 1.312271 1 13.593349 0.0", - "sugar-glyc-d2b34": "charmm -0.2683885 1 -83.0853785 0.0", - "sugar-glyc-d2b6": "charmm -0.542714 1 -26.391433 0.0", - "sugar-glyc-d3a": "charmm -6.74014666 1 -83.661744 0.0", - "sugar-glyc-d3b": "charmm -0.05605633 1 -42.276276 0.0" + "sugar-glyc-d1-3": "charmm -0.1801345 1 -123.0662189 0.0", + "sugar-glyc-d1-4": "charmm -0.8522 1 -146.907595 0.0", + "sugar-glyc-d1-6": "charmm 0.4714055 1 0.8067885 0.0", + "sugar-glyc-d2-a-34": "charmm -0.819724 1 -65.408620 0.0", + "sugar-glyc-d2-a-6": "charmm 1.312271 1 13.593349 0.0", + "sugar-glyc-d2-b-34": "charmm -0.2683885 1 -83.0853785 0.0", + "sugar-glyc-d2-b-6": "charmm -0.542714 1 -26.391433 0.0", + "sugar-glyc-d3-a": "charmm -6.74014666 1 -83.661744 0.0", + "sugar-glyc-d3-b": "charmm -0.05605633 1 -42.276276 0.0" + }, + "improper":{ + "dipole-cone-1": "dipole/cone 200 120 60", + "dipole-cone-2": "dipole/cone 200 -120 60" } } } diff --git a/data/elba-sugar/mol-gulose.json b/data/elba-sugar/mol-gulose.json index 2d3411f7193c47827f5cc9edf12fdb0281483778..3cb32b972ca965a4475c90993a0a47d54dc52e1d 100644 --- a/data/elba-sugar/mol-gulose.json +++ b/data/elba-sugar/mol-gulose.json @@ -31,7 +31,7 @@ "templates":["0KA", "4XX"] }, "6KA":{ - "templates":["0KA", "5XX"] + "templates":["0KA", "6XX"] }, "1KB":{ "templates":["0KB", "1XX"] diff --git a/lib/moldatabase.py b/lib/moldatabase.py index f53797551ed19705b549ac1cbaeb8ec2c983dbe7..9a74bf45af8d084042d58b1563135ee0eeb6d9fe 100644 --- a/lib/moldatabase.py +++ b/lib/moldatabase.py @@ -21,7 +21,7 @@ class Molecule: self.dihedrals = [] self.impropers = [] self.polymer_type = set() - self.templates = set() + self.templates = [] for key, value in kwargs.items(): try: @@ -76,6 +76,7 @@ class MolDatabase: for mol in self.molecules.values(): used_templates = set() while mol.templates: + print(mol.templates) template = mol.templates.pop() if template not in used_templates: mol.extend(self.molecules[template]) diff --git a/test/data/glc.pdb b/test/data/glc.pdb index d224037a1e5485a8fd19bc598d37733483fa6119..37e1ef6bd0b45f0b11cf1420c759466f88620d5b 100644 --- a/test/data/glc.pdb +++ b/test/data/glc.pdb @@ -1,8 +1,17 @@ -CRYST1 10.000 10.000 10.000 90.00 90.00 90.00 P 1 1 -ATOM 1 C1 0GA X 1 5.378 5.919 6.028 0.00 0.00 -ATOM 2 C2 0GA X 1 3.931 5.794 5.771 0.00 0.00 -ATOM 3 C3 0GA X 1 3.661 4.581 4.907 0.00 0.00 -ATOM 4 C4 0GA X 1 4.331 4.828 3.525 0.00 0.00 -ATOM 5 C5 0GA X 1 5.816 5.052 3.761 0.00 0.00 -ATOM 6 O5 0GA X 1 6.007 6.100 4.727 0.00 0.00 -END +TITLE 1 +REMARK THIS IS A SIMULATION BOX +CRYST1 21.909 21.486 21.995 90.00 90.00 90.00 P 1 1 +MODEL 1 +ATOM 1 C1 0GA 1 10.560 9.630 18.250 1.00 0.00 +ATOM 2 C2 0GA 1 9.870 8.550 19.060 1.00 0.00 +ATOM 3 C3 0GA 1 9.170 8.920 20.360 1.00 0.00 +ATOM 4 C4 0GA 1 9.900 10.020 21.110 1.00 0.00 +ATOM 5 C5 0GA 1 10.550 11.090 20.250 1.00 0.00 +ATOM 6 O5 0GA 1 11.310 10.500 19.160 1.00 0.00 +ATOM 7 D1 0GA 1 11.060 9.270 18.610 1.00 0.00 +ATOM 8 D2 0GA 1 10.260 9.030 19.420 1.00 0.00 +ATOM 9 D3 0GA 1 9.260 9.490 19.930 1.00 0.00 +ATOM 10 D4 0GA 1 10.370 9.710 20.680 1.00 0.00 +ATOM 11 D5 0GA 1 10.040 10.620 19.930 1.00 0.00 +TER +ENDMDL diff --git a/test/data/glc_moldb.json b/test/data/glc_moldb.json new file mode 100644 index 0000000000000000000000000000000000000000..42678aba412040d92dd0fa738eb6f586a44b3be7 --- /dev/null +++ b/test/data/glc_moldb.json @@ -0,0 +1,197 @@ +{ + "notes": "These parameters are temporary", + "molecules": { + "0XX":{ + "polymer_type":["sugar"], + "atoms":[ + {"name": "C1", "type": "MEOH"}, + {"name": "C2", "type": "MEOH"}, + {"name": "C3", "type": "MEOH"}, + {"name": "C4", "type": "MEOH"}, + {"name": "C5", "type": "ETOH"}, + {"name": "O5", "type": "OXY"} + ], + "lengths":[ + {"type": "sugar-ring", "atoms":["C1", "C2"]}, + {"type": "sugar-ring", "atoms":["C2", "C3"]}, + {"type": "sugar-ring", "atoms":["C3", "C4"]}, + {"type": "sugar-ring", "atoms":["C4", "C5"]}, + {"type": "sugar-ring", "atoms":["C5", "O5"]}, + {"type": "sugar-ring", "atoms":["O5", "C1"]} + ], + "angles":[ + {"type": "sugar-ring", "atoms":["C1", "C2", "C3"]}, + {"type": "sugar-ring", "atoms":["C2", "C3", "C4"]}, + {"type": "sugar-ring", "atoms":["C3", "C4", "C5"]}, + {"type": "sugar-ring", "atoms":["C4", "C5", "O5"]}, + {"type": "sugar-ring", "atoms":["C5", "O5", "C1"]}, + {"type": "sugar-ring", "atoms":["O5", "C1", "C2"]} + ] + }, + "0GX": { + "templates": [ + "0XX" + ], + "dihedrals": [ + { + "type": "sugar-dih-1", + "atoms": [ + "C1", + "C2", + "C3", + "C4" + ] + }, + { + "type": "sugar-dih-2", + "atoms": [ + "C2", + "C3", + "C4", + "C5" + ] + }, + { + "type": "sugar-dih-1", + "atoms": [ + "C3", + "C4", + "C5", + "O5" + ] + }, + { + "type": "sugar-dih-2", + "atoms": [ + "C4", + "C5", + "O5", + "C1" + ] + }, + { + "type": "sugar-dih-1", + "atoms": [ + "C5", + "O5", + "C1", + "C2" + ] + }, + { + "type": "sugar-dih-2", + "atoms": [ + "O5", + "C1", + "C2", + "C3" + ] + } + ] + }, + "0GA": { + "templates": [ + "0GX" + ], + "impropers": [ + { + "type": "dipole-cone-1", + "atoms": [ + "C1", + "C2", + "O5", + "C1" + ] + }, + { + "type": "dipole-cone-1", + "atoms": [ + "C2", + "C3", + "C1", + "C2" + ] + }, + { + "type": "dipole-cone-2", + "atoms": [ + "C3", + "C4", + "C2", + "C3" + ] + }, + { + "type": "dipole-cone-1", + "atoms": [ + "C4", + "C5", + "C3", + "C4" + ] + }, + { + "type": "dipole-cone-2", + "atoms": [ + "C5", + "O5", + "C4", + "C5" + ] + } + ] + }, + "0GB": { + "templates": [ + "0GX" + ], + "impropers": [ + { + "type": "dipole-cone-2", + "atoms": [ + "C1", + "C2", + "O5", + "C1" + ] + }, + { + "type": "dipole-cone-1", + "atoms": [ + "C2", + "C3", + "C1", + "C2" + ] + }, + { + "type": "dipole-cone-2", + "atoms": [ + "C3", + "C4", + "C2", + "C3" + ] + }, + { + "type": "dipole-cone-1", + "atoms": [ + "C4", + "C5", + "C3", + "C4" + ] + }, + { + "type": "dipole-cone-2", + "atoms": [ + "C5", + "O5", + "C4", + "C5" + ] + } + ] + } + } +} diff --git a/test/test_bonddatabase.py b/test/test_bonddatabase.py index 033b77ead3426e690ffefe9c97e39f3c5c44d0b5..75fcd9c0d97917d42bac74bbc00f6c1f356644dc 100644 --- a/test/test_bonddatabase.py +++ b/test/test_bonddatabase.py @@ -21,9 +21,5 @@ class TestBondDatabase(unittest.TestCase): self.assertEqual(db.dihedral["sugar-dih-1"].style, "fourier") self.assertEqual(db.dihedral["sugar-dih-1"].params, "2 1.00 3 0 0.25 1 -120") - self.assertTrue("dipole-cone-1" in db.improper) - self.assertEqual(db.improper["dipole-cone-1"].style, "dipole/cone") - self.assertEqual(db.improper["dipole-cone-1"].params, "200 120 60") - if __name__ == '__main__': unittest.main() diff --git a/test/test_moldatabase.py b/test/test_moldatabase.py index e2d27b69150b05ec8576a4902d2f91a2d2af962b..bc563996a3d28f44c9baad0db479b7cf370cccf8 100644 --- a/test/test_moldatabase.py +++ b/test/test_moldatabase.py @@ -16,27 +16,25 @@ class TestMolDatabase(unittest.TestCase): def test_read_lengths(self): db = MolDatabase() - self.assertEqual(db.molecules["0GA"].lengths[0].type, "sugar-ring") - self.assertEqual(db.molecules["0GA"].lengths[0].atoms[0], "C1") - self.assertEqual(db.molecules["0GA"].lengths[0].atoms[1], "C2") - self.assertEqual(db.molecules["0GA"].lengths[5].type, "sugar-ring") - self.assertEqual(db.molecules["0GA"].lengths[5].atoms[0], "O5") - self.assertEqual(db.molecules["0GA"].lengths[5].atoms[1], "C1") - self.assertEqual(6, len(db.molecules["0GA"].lengths)) - self.assertEqual(7, len(db.molecules["3GA"].lengths)) + self.assertEqual(db.molecules["0XX"].lengths[0].type, "sugar-ring") + self.assertEqual(db.molecules["0XX"].lengths[0].atoms[0], "C1") + self.assertEqual(db.molecules["0XX"].lengths[0].atoms[1], "C2") + self.assertEqual(db.molecules["0XX"].lengths[5].type, "sugar-ring") + self.assertEqual(db.molecules["0XX"].lengths[5].atoms[0], "O5") + self.assertEqual(db.molecules["0XX"].lengths[5].atoms[1], "C1") + self.assertEqual(21, len(db.molecules["0XX"].lengths)) def test_read_angles(self): db = MolDatabase() - self.assertEqual(db.molecules["0GA"].angles[0].type, "sugar-ring") - self.assertEqual(db.molecules["0GA"].angles[0].atoms[0], "C1") - self.assertEqual(db.molecules["0GA"].angles[0].atoms[1], "C2") - self.assertEqual(db.molecules["0GA"].angles[0].atoms[2], "C3") - self.assertEqual(db.molecules["0GA"].angles[5].type, "sugar-ring") - self.assertEqual(db.molecules["0GA"].angles[5].atoms[0], "O5") - self.assertEqual(db.molecules["0GA"].angles[5].atoms[1], "C1") - self.assertEqual(db.molecules["0GA"].angles[5].atoms[2], "C2") - self.assertEqual(6, len(db.molecules["0GA"].angles)) - self.assertEqual(6, len(db.molecules["3GA"].angles)) + self.assertEqual(db.molecules["0XX"].angles[0].type, "sugar-ring") + self.assertEqual(db.molecules["0XX"].angles[0].atoms[0], "C1") + self.assertEqual(db.molecules["0XX"].angles[0].atoms[1], "C2") + self.assertEqual(db.molecules["0XX"].angles[0].atoms[2], "C3") + self.assertEqual(db.molecules["0XX"].angles[5].type, "sugar-ring") + self.assertEqual(db.molecules["0XX"].angles[5].atoms[0], "O5") + self.assertEqual(db.molecules["0XX"].angles[5].atoms[1], "C1") + self.assertEqual(db.molecules["0XX"].angles[5].atoms[2], "C2") + self.assertEqual(11, len(db.molecules["0XX"].angles)) def test_template(self): db = MolDatabase("data/mol-elba-sugar.json") @@ -48,11 +46,11 @@ class TestMolDatabase(unittest.TestCase): self.assertEqual(db.molecules["1GA"].lengths[1].atoms[0], "C1") self.assertEqual(db.molecules["1GA"].lengths[1].atoms[1], "C2") - self.assertEqual(6, len(db.molecules["0GA"].lengths)) - self.assertEqual(7, len(db.molecules["1GA"].lengths)) + self.assertEqual(21, len(db.molecules["0GA"].lengths)) + self.assertEqual(22, len(db.molecules["1GA"].lengths)) - self.assertEqual(6, len(db.molecules["0GA"].angles)) - self.assertEqual(6, len(db.molecules["1GA"].angles)) + self.assertEqual(11, len(db.molecules["0GA"].angles)) + self.assertEqual(13, len(db.molecules["1GA"].angles)) def test_template_simple(self): db = MolDatabase("test/data/template.json") diff --git a/test/test_pdb2lmp.py b/test/test_pdb2lmp.py index b0989f6c4b08173a28f1aab7b83981d137ba0e50..a4854f8a79ee5120c94f873b17035faa61ea636a 100644 --- a/test/test_pdb2lmp.py +++ b/test/test_pdb2lmp.py @@ -18,27 +18,25 @@ class TestPDB2LMP(unittest.TestCase): conv = PDB2LMP("test/data/glc.pdb") conv.collect_types() self.assertListEqual(conv.moltypes, ["0GA"]) - self.assertListEqual(conv.atomtypes, ["MEOH", "ETOH", "OXY", "WAT"]) - self.assertListEqual(conv.lentypes, ["sugar-ring"]) - self.assertListEqual(conv.angtypes, ["sugar-ring"]) - self.assertEqual(conv.natoms.total, 6) - self.assertEqual(conv.natoms.types, 4) - self.assertEqual(conv.nlengths.total, 6) - self.assertEqual(conv.nlengths.types, 1) - self.assertEqual(conv.nangles.total, 6) - self.assertEqual(conv.nangles.types, 1) + self.assertListEqual(conv.atomtypes, ["MEOH", "ETOH", "OXY", "DUM", "WAT"]) + self.assertListEqual(conv.lentypes, ["sugar-ring", "sugar-dum-adj", "sugar-dum"]) + self.assertListEqual(conv.angtypes, ["sugar-ring", "sugar-dipole"]) + self.assertEqual(conv.natoms.total, 11) + self.assertEqual(conv.natoms.types, 5) + self.assertEqual(conv.nlengths.total, 21) + self.assertEqual(conv.nlengths.types, 3) + self.assertEqual(conv.nangles.total, 11) + self.assertEqual(conv.nangles.types, 2) self.assertEqual(conv.ndihedrals.total, 6) self.assertEqual(conv.ndihedrals.types, 2) - self.assertEqual(conv.nimpropers.total, 5) - self.assertEqual(conv.nimpropers.types, 2) def test_collect_types_no_add_water(self): conv = PDB2LMP("test/data/glc.pdb") conv.collect_types(add_water=False) self.assertListEqual(conv.moltypes, ["0GA"]) - self.assertListEqual(conv.atomtypes, ["MEOH", "ETOH", "OXY"]) - self.assertEqual(conv.natoms.total, 6) - self.assertEqual(conv.natoms.types, 3) + self.assertListEqual(conv.atomtypes, ["MEOH", "ETOH", "OXY", "DUM"]) + self.assertEqual(conv.natoms.total, 11) + self.assertEqual(conv.natoms.types, 4) def test_collect_types_subset(self): conv = PDB2LMP("test/data/ala-aa.gro") @@ -49,7 +47,8 @@ class TestPDB2LMP(unittest.TestCase): self.assertEqual(conv.natoms.types, 4) def test_collect_types_multiple_residues(self): - conv = PDB2LMP("test/data/glc_crystal.gro") + moldb = MolDatabase("test/data/glc_moldb.json") + conv = PDB2LMP("test/data/glc_crystal.gro", moldb=moldb) conv.collect_types() self.assertListEqual(conv.moltypes, ["0GB"]) self.assertListEqual(conv.atomtypes, ["MEOH", "ETOH", "OXY", "WAT"])