def setUpClass(cls): mass_info = [ ("A", "H"), ("B", Element("C")), ("C", Element("O")), ("D", 1.00794), ] nonbond_coeffs = [ [1, 1, 1.1225], [1, 1.175, 1.31894], [1, 1.55, 1.73988], [1, 1, 1.1225], [1, 1.35, 4], [1, 1.725, 1.93631], [1, 1.175, 1.31894], [1, 2.1, 4], [1, 1.55, 1.73988], [1, 1, 1.1225], ] topo_coeffs = { "Bond Coeffs": [ {"coeffs": [50, 0.659469], "types": [("A", "B"), ("C", "D")]}, {"coeffs": [50, 0.855906], "types": [("B", "C")]}, ] } cls.virus = ForceField(mass_info=mass_info, nonbond_coeffs=nonbond_coeffs, topo_coeffs=topo_coeffs) cls.ethane = ForceField.from_file(os.path.join(test_dir, "ff_ethane.yaml"))
def setUpClass(cls): mass_info = [("H", Element("H")), ("C", "C")] pair_coeffs = [[0.0380000011, 2.449971454], [0.1479999981, 3.6170487995]] mol_coeffs = { "Bond Coeffs": [{ "coeffs": [480.0, 1.34], "types": [("C", "C")] }, { "coeffs": [363.4164, 1.08], "types": [("H", "C")] }], "Angle Coeffs": [{ "coeffs": [90.0, 120.0], "types": [("C", "C", "C")] }, { "coeffs": [37.0, 120.0], "types": [("H", "C", "C")] }], "Dihedral Coeffs": [{ "coeffs": [3.0, -1, 2], "types": [("C", "C", "C", "C"), ("H", "C", "C", "C"), ("H", "C", "C", "H")] }], "Improper Coeffs": [{ "coeffs": [0.37, -1, 2], "types": [("H", "C", "C", "C")] }] } cls.benzene = ForceField(mass_info=mass_info, pair_coeffs=pair_coeffs, mol_coeffs=mol_coeffs) cls.virus = ForceField.from_file( os.path.join(test_dir, "ff_virus.yaml"))
def _get_gaussian_ff_top_single(self, filename=None): """ run antechamber using gaussian output file, then run parmchk to generate missing force field parameters. Store and return the force field and topology information in ff_mol. Args: filename: gaussian output file of the molecule Returns: Amberff namedtuple object that contains information on force field and topology """ scratch = tempfile.gettempdir() Amberff = namedtuple("Amberff", ["force_field", "topology"]) with ScratchDir(scratch, copy_from_current_on_enter=True, copy_to_current_on_exit=True) as d: # self._convert_to_pdb(mol, 'mol.pdb') # self.molname = filename.split('.')[0] self._run_antechamber(filename) self._run_parmchk() # if antechamber can't find parameters go to gaff_example.dat try: mol = Molecule.from_file('mol.rtf') print('mol.rtf file exists') except TopCorruptionException: correct_corrupted_top_files('mol.rtf', 'gaff_data.txt') top = Topology.from_file('mol.rtf') print('mol.rtf file does not exist') try: gff = ForceField.from_file('mol.frcmod') except FFCorruptionException: correct_corrupted_frcmod_files('ANTECHAMBER.FRCMOD', 'gaff_data.txt') gff = ForceField.from_file('ANTECHAMBER.FRCMOD') # gff.set_atom_mappings('ANTECHAMBER_AC.AC') # gff.read_charges() # decorate the molecule with the sire property "atomname" #mol.add_site_property("atomname", (list(gff.atom_index.values()))) return Amberff(gff, top)
def setUpClass(cls): mass_info = [("A", "H"), ("B", Element("C")), ("C", Element("O")), ("D", 1.00794)] nonbond_coeffs = [[1, 1, 1.1225], [1, 1.175, 1.31894], [1, 1.55, 1.73988], [1, 1, 1.1225 ], [1, 1.35, 4], [1, 1.725, 1.93631], [1, 1.175, 1.31894], [1, 2.1, 4], [1, 1.55, 1.73988], [1, 1, 1.1225 ]] topo_coeffs = {"Bond Coeffs": [{"coeffs": [50, 0.659469], "types": [("A", "B"), ("C", "D")]}, {"coeffs": [50, 0.855906], "types": [("B", "C")]}]} cls.virus = ForceField(mass_info=mass_info, nonbond_coeffs=nonbond_coeffs, topo_coeffs=topo_coeffs) cls.ethane = ForceField.from_file(os.path.join(test_dir, "ff_ethane.yaml"))
def setUpClass(cls): mass_info = [("H", Element("H")), ("C", "C")] pair_coeffs = [[0.0380000011, 2.449971454], [0.1479999981, 3.6170487995]] mol_coeffs = { "Bond Coeffs": [{"coeffs": [480.0, 1.34], "types": [("C", "C")]}, {"coeffs": [363.4164, 1.08], "types": [("H", "C")]}], "Angle Coeffs": [{"coeffs": [90.0, 120.0], "types": [("C", "C", "C")]}, {"coeffs": [37.0, 120.0], "types": [("H", "C", "C")]}], "Dihedral Coeffs": [{"coeffs": [3.0, -1, 2], "types": [("C", "C", "C", "C"), ("H", "C", "C", "C"), ("H", "C", "C", "H")]}], "Improper Coeffs": [{"coeffs": [0.37, -1, 2], "types": [("H", "C", "C", "C")]}] } cls.benzene = ForceField(mass_info=mass_info, pair_coeffs=pair_coeffs, mol_coeffs=mol_coeffs) cls.virus = ForceField.from_file(os.path.join(test_dir, "ff_virus.yaml"))
def test_from_ff_and_topologies(self): ff = ForceField.from_file(os.path.join(test_dir, "ff_peptide.yaml")) with open(os.path.join(test_dir, "topologies_peptide.json")) as f: topo_dicts = json.load(f) topologies = [Topology.from_dict(d) for d in topo_dicts] peptide = LammpsData.\ from_ff_and_topologies(ff=ff, topologies=topologies, box_bounds=[[-50, 150]] * 3) self.assertListEqual(peptide.masses, ff.masses) force_field = ff.get_pair_coeffs() for kw in ff.mol_coeffs.keys(): sec, _ = ff.get_coeffs_and_mapper(kw) force_field.update(sec) self.assertDictEqual(peptide.force_field, force_field) back_atom_map = {v: k for k, v in ff.atom_map.items()} # test the 1st topology, the peptide pep = topologies[0] # atoms and velocities sections i = random.randint(0, len(pep.sites) - 1) site = pep.sites[i] in_atoms = peptide.atoms[i] self.assertEqual(in_atoms["molecule-ID"], 1) self.assertEqual(in_atoms["id"], i + 1) self.assertEqual(in_atoms["type"], ff.atom_map[site.properties["ff_map"]]) self.assertEqual(in_atoms["q"], pep.charges[i]) self.assertEqual(in_atoms["x"], site.x) self.assertEqual(in_atoms["y"], site.y) self.assertEqual(in_atoms["z"], site.z) in_velos = peptide.velocities[i] self.assertEqual(in_velos["id"], i + 1) self.assertListEqual(in_velos["velocity"], pep.velocities[i]) # topology sections for t in ["Bond", "Angle", "Dihedral", "Improper"]: topo_sec = "%ss" % t ff_sec = "%s Coeffs" % t kw = t.lower() i = random.randint(0, len(pep.topologies[topo_sec]) - 1) sample = pep.topologies[topo_sec][i] in_topos = peptide.topology[topo_sec][i] self.assertEqual(in_topos["id"], i + 1, "%s" % t) np.testing.assert_array_equal(in_topos[kw], np.array(sample) + 1, "%s" % t) topo_type_id = in_topos["type"] types = ff.mol_coeffs[ff_sec][topo_type_id - 1]["types"] sample_type = tuple([pep.sites[j].properties["ff_map"] for j in sample]) self.assertIn(sample_type, types, "%s" % t) # test a random solvent (water) molecule i = random.randint(1, len(topologies) - 1) solv = topologies[i] stack = {"Atoms": 0, "Bonds": 0, "Angles": 0} for topo in topologies[:i]: stack["Atoms"] += len(topo.sites) stack["Bonds"] += len(topo.topologies["Bonds"]) stack["Angles"] += len(topo.topologies["Angles"]) # atoms and velocities sections in_atoms = [d for d in peptide.atoms if d["molecule-ID"] == i + 1] self.assertEqual(len(in_atoms), len(solv.sites)) aids, types, charges, coords = [], [], [], [] for d in in_atoms: aids.append(d["id"]) types.append(d["type"]) charges.append(d["q"]) coords.append([d["x"], d["y"], d["z"]]) np.testing.assert_array_equal(aids, np.arange(len(solv.sites)) + stack["Atoms"] + 1) self.assertListEqual(types, [ff.atom_map[t] for t in solv.types]) self.assertListEqual(charges, solv.charges) np.testing.assert_array_equal(coords, solv.sites.cart_coords) in_velos = peptide.velocities[stack["Atoms"]: stack["Atoms"] + len(in_atoms)] vids, velocities = [], [] for d in in_velos: vids.append(d["id"]) velocities.append(d["velocity"]) self.assertListEqual(vids, aids) np.testing.assert_array_equal(velocities, solv.velocities) # topology sections for t in ["Bond", "Angle"]: topo_sec = "%ss" % t ff_sec = "%s Coeffs" % t kw = t.lower() sample = solv.topologies[topo_sec][0] i = stack[topo_sec] in_topos = peptide.topology[topo_sec][i] self.assertEqual(in_topos["id"], i + 1, "%s" % t) np.testing.assert_array_equal(in_topos[kw], np.array(sample) + stack["Atoms"] + 1, "%s" % t) topo_type_id = in_topos["type"] types = ff.mol_coeffs[ff_sec][topo_type_id - 1]["types"] sample_type = tuple([solv.sites[j].properties["ff_map"] for j in sample]) self.assertIn(sample_type, types, "%s" % t)
def test_from_ff_and_topologies(self): ff = ForceField.from_file(os.path.join(test_dir, "ff_peptide.yaml")) with open(os.path.join(test_dir, "topologies_peptide.json")) as f: topo_dicts = json.load(f) topologies = [Topology.from_dict(d) for d in topo_dicts] peptide = LammpsData.\ from_ff_and_topologies(ff=ff, topologies=topologies, box_bounds=[[-50, 150]] * 3) self.assertListEqual(peptide.masses, ff.masses) force_field = ff.get_pair_coeffs() for kw in ff.mol_coeffs.keys(): sec, _ = ff.get_coeffs_and_mapper(kw) force_field.update(sec) self.assertDictEqual(peptide.force_field, force_field) back_atom_map = {v: k for k, v in ff.atom_map.items()} # test the 1st topology, the peptide pep = topologies[0] # atoms and velocities sections i = random.randint(0, len(pep.sites) - 1) site = pep.sites[i] in_atoms = peptide.atoms[i] self.assertEqual(in_atoms["molecule-ID"], 1) self.assertEqual(in_atoms["id"], i + 1) self.assertEqual(in_atoms["type"], ff.atom_map[site.properties["ff_map"]]) self.assertEqual(in_atoms["q"], pep.charges[i]) self.assertEqual(in_atoms["x"], site.x) self.assertEqual(in_atoms["y"], site.y) self.assertEqual(in_atoms["z"], site.z) in_velos = peptide.velocities[i] self.assertEqual(in_velos["id"], i + 1) self.assertListEqual(in_velos["velocity"], pep.velocities[i]) # topology sections for t in ["Bond", "Angle", "Dihedral", "Improper"]: topo_sec = "%ss" % t ff_sec = "%s Coeffs" % t kw = t.lower() i = random.randint(0, len(pep.topologies[topo_sec]) - 1) sample = pep.topologies[topo_sec][i] in_topos = peptide.topology[topo_sec][i] self.assertEqual(in_topos["id"], i + 1, "%s" % t) np.testing.assert_array_equal(in_topos[kw], np.array(sample) + 1, "%s" % t) topo_type_id = in_topos["type"] types = ff.mol_coeffs[ff_sec][topo_type_id - 1]["types"] sample_type = tuple( [pep.sites[j].properties["ff_map"] for j in sample]) self.assertIn(sample_type, types, "%s" % t) # test a random solvent (water) molecule i = random.randint(1, len(topologies) - 1) solv = topologies[i] stack = {"Atoms": 0, "Bonds": 0, "Angles": 0} for topo in topologies[:i]: stack["Atoms"] += len(topo.sites) stack["Bonds"] += len(topo.topologies["Bonds"]) stack["Angles"] += len(topo.topologies["Angles"]) # atoms and velocities sections in_atoms = [d for d in peptide.atoms if d["molecule-ID"] == i + 1] self.assertEqual(len(in_atoms), len(solv.sites)) aids, types, charges, coords = [], [], [], [] for d in in_atoms: aids.append(d["id"]) types.append(d["type"]) charges.append(d["q"]) coords.append([d["x"], d["y"], d["z"]]) np.testing.assert_array_equal( aids, np.arange(len(solv.sites)) + stack["Atoms"] + 1) self.assertListEqual(types, [ff.atom_map[t] for t in solv.types]) self.assertListEqual(charges, solv.charges) np.testing.assert_array_equal(coords, solv.sites.cart_coords) in_velos = peptide.velocities[stack["Atoms"]:stack["Atoms"] + len(in_atoms)] vids, velocities = [], [] for d in in_velos: vids.append(d["id"]) velocities.append(d["velocity"]) self.assertListEqual(vids, aids) np.testing.assert_array_equal(velocities, solv.velocities) # topology sections for t in ["Bond", "Angle"]: topo_sec = "%ss" % t ff_sec = "%s Coeffs" % t kw = t.lower() sample = solv.topologies[topo_sec][0] i = stack[topo_sec] in_topos = peptide.topology[topo_sec][i] self.assertEqual(in_topos["id"], i + 1, "%s" % t) np.testing.assert_array_equal( in_topos[kw], np.array(sample) + stack["Atoms"] + 1, "%s" % t) topo_type_id = in_topos["type"] types = ff.mol_coeffs[ff_sec][topo_type_id - 1]["types"] sample_type = tuple( [solv.sites[j].properties["ff_map"] for j in sample]) self.assertIn(sample_type, types, "%s" % t)