def test_polymer_chain_topologies(self): topology_random = Topology.from_molecule(self.peo_polymer.molecule, tol=0.1) topology_linear = Topology.from_molecule( self.peo_polymer_linear.molecule, tol=0.1) self.assertNotEqual(topology_linear.bonds, topology_random.bonds) self.assertNotEqual(topology_linear.angles, topology_random.angles) self.assertNotEqual(topology_linear.dihedrals, topology_random.dihedrals)
def setUp(self): self.polymer_linear = Molecule.from_file( os.path.join(test_dir, "polymer_linear.xyz")) charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.1187, 0.0861, 0.0861, 0.0861] ff_map = ["C3", "H3", "H3", "H3", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C3", "H3", "H3", "H3"] self.polymer_linear.add_site_property("charge", charges) self.polymer_linear.add_site_property("ff_map", ff_map) self.topology = Topology.from_molecule(self.polymer_linear) self.forcefield = ForceField.from_file( os.path.join(test_dir, "ffmap_data.yaml")) box_size = [[0.0, 50], [0.0, 50], [0.0, 50]] self.lammps_ff_data = LammpsForceFieldData.from_forcefield_and_topology( [self.polymer_linear], [1], box_size, self.polymer_linear, self.forcefield, [self.topology])
def test_atoms_data_with_ff_map(self): natoms, natom_types, atomic_masses_dict = \ LammpsForceFieldData.get_basic_system_info(self.polymer_linear_ff_decorated) topology = Topology.from_molecule(self.polymer_linear_ff_decorated, ff_map="ff_map") atoms_data, molid_to_atomid = LammpsForceFieldData.get_atoms_data( [self.polymer_linear_ff_decorated], [1], self.polymer_linear_ff_decorated, atomic_masses_dict, [topology]) for i, atom in enumerate(atoms_data): key = self.polymer_linear_ff_decorated[i].ff_map self.assertEqual(atom[2], atomic_masses_dict[key][0])
def setUpClass(cls): polymer_chain = Molecule.from_file(os.path.join(test_dir, "polymer_chain.xyz")) polymer_linear = Molecule.from_file(os.path.join(test_dir, "polymer_linear.xyz")) cls.polymer_matrix = Molecule.from_file(os.path.join(test_dir, "polymer_matrix.xyz")) charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861, -0.0326, 0.0861, 0.0861, -0.2792, -0.1187, 0.0861, 0.0861, 0.0861] polymer_linear.add_site_property("charge", charges) topology = Topology.from_molecule(polymer_linear) cls.polymer_linear_ff_decorated = Molecule.from_file( os.path.join(test_dir,"polymer_linear.xyz")) ff_map = ['C2', 'H3', 'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'C2', 'H3', 'H2', 'O', 'C2', 'H3', 'H2', 'C3', 'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'C2', 'H3', 'H2', 'O', 'C2', 'H3', 'H2', 'C3', 'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'C2', 'H3', 'H2', 'O', 'C2', 'H3', 'H2', 'C3', 'H2', 'H3', 'O', 'C3', 'H2', 'H3', 'H2'] cls.polymer_linear_ff_decorated.add_site_property("ff_map", ff_map) atoms = OrderedDict([("C", "C"), ("H", "H"), ("O", "O")]) bonds = OrderedDict([((u'C', u'O'), [1000, 1.4115]), ((u'C', u'H'), [1000, 1.1041]), ((u'C', u'C'), [1000, 1.5075])]) pairs = OrderedDict([((u'O', u'O'), [75844.8, 0.2461, 396.9]), ((u'H', u'H'), [2649.6, 0.2674, 27.22]), ((u'C', u'C'), [14976.0, 0.3236, 637.6])]) angles = OrderedDict([((u'C', u'C', u'H'), [42.9, 110.1]), ((u'H', u'C', u'H'), [38.5, 109.47]), ((u'H', u'C', u'O'), [56.0, 109.48]), ((u'C', u'C', u'O'), [86.0, 108.54]), ((u'C', u'O', u'C'), [74.5, 108.05])]) dihedrals = OrderedDict([((u'H', u'C', u'O', u'C'), [0.0, 0.0, -0.73, 0.0]), ((u'H', u'C', u'C', u'H'), [0.0, 0.0, 0.28, 0.0]), ((u'C', u'C', u'O', u'C'), [1.76, 0.67, 0.04, 0.0]), ((u'H', u'C', u'C', u'O'), [0.0, 0.0, 0.28, 0.0]), ((u'O', u'C', u'C', u'O'), [0.41, -2.1, -0.6, -0.82])]) forcefield = ForceField(atoms, bonds, angles, dihedrals=dihedrals, pairs=pairs) cls.molecules = [polymer_chain] * 3 cls.mols_number = [7, 3, 1] box_size = [[0.0, 50], [0.0, 50], [0.0, 50]] cls.topologies = [topology] * len(cls.molecules) cls.lammps_ff_data_1 = LammpsForceFieldData.from_forcefield_and_topology( cls.molecules, cls.mols_number, box_size, cls.polymer_matrix, forcefield, cls.topologies)
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: top = Topology.from_file('mol.rtf') except TopCorruptionException: correct_corrupted_top_files('mol.rtf', 'gaff_data.txt') top = Topology.from_file('mol.rtf') 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 get_packmol_wf(input_file, user_settings, constituent_molecules, packing_config, forcefield, final_box_size, ff_site_property=None, tolerance=2.0, filetype="xyz", control_params=None, lammps_cmd="lmp_serial", dump_filenames=None, db_file=None, name="Packmol Lammps Wflow"): """ Returns workflow that uses Packmol to pack the constituent molecules into the given configuration and then run lammps on the final packed molecule. Useful for polymer studies. Args: input_file (str): path to lammps input(or template) file. user_settings (dict): if the input_file is a tempalte file then this dict contains the key value pairs for the template file. constituent_molecules ([Molecules]): list of pymatgen Molecule objects packing_config ([dict]): list of configuration dictionaries, one for each constituent molecule. forcefield (ForceField): pymatgen.io.lammps.forcefield.ForceField object final_box_size ([list]): list of list of low and high values for each dimension [[xlow, xhigh], ...] ff_site_property (str): the name of the site property used for forcefield mapping tolerance (float): packmol tolerance filetype (str): packmol i/o file type. control_params (dict): packmol control params lammps_cmd (string): lammps command to run (skip the input file). dump_filenames ([str]): list of dump file names db_file (string): path to the db file. name (str): workflow name Returns: Workflow """ packmol_output_file = "packed.{}".format(filetype) mols_number = [mol_config["number"] for mol_config in packing_config] topologies = [] for mol in constituent_molecules: topologies.append(Topology.from_molecule(mol, ff_map=ff_site_property)) fw_packmol = PackmolFW(constituent_molecules, packing_config, tolerance=tolerance, filetype=filetype, control_params=control_params, copy_to_current_on_exit=True, output_file=packmol_output_file, site_property=ff_site_property), fw_lammps = LammpsForceFieldFW(input_file, packmol_output_file, forcefield, final_box_size, topologies=topologies, constituent_molecules=constituent_molecules, mols_number=mols_number, user_settings=user_settings, ff_site_property=ff_site_property, input_filename="lammps.in", lammps_cmd=lammps_cmd, db_file=db_file, log_filename="lammps.log", dump_filenames=dump_filenames, parents=[fw_packmol]) return Workflow([fw_packmol, fw_lammps], name=name)
def test_topology(self): atoms = [['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['C', 'C'], ['O', 'O'], ['C', 'C'], ['C', 'C'], ['O', 'O']] bonds = [[11, 19, ('C', 'H')], [12, 13, ('O', 'C')], [13, 20, ('C', 'H')], [13, 21, ('C', 'H')], [19, 22, ('H', 'C')], [22, 23, ('C', 'O')], [22, 29, ('C', 'H')], [23, 24, ('O', 'C')], [24, 25, ('C', 'C')], [24, 30, ('C', 'H')]] angles = [[8, 9, 10, ('C', 'O', 'C')], [9, 10, 11, ('O', 'C', 'C')], [9, 10, 16, ('O', 'C', 'H')], [9, 10, 17, ('O', 'C', 'H')], [11, 10, 16, ('C', 'C', 'H')], [11, 10, 17, ('C', 'C', 'H')], [10, 11, 12, ('C', 'C', 'O')], [10, 11, 18, ('C', 'C', 'H')], [10, 11, 19, ('C', 'C', 'H')], [16, 10, 17, ('H', 'C', 'H')]] dihedrals = [[8, 9, 10, 16, ('C', 'O', 'C', 'H')], [8, 9, 10, 17, ('C', 'O', 'C', 'H')], [15, 8, 9, 10, ('H', 'C', 'O', 'C')], [9, 10, 11, 12, ('O', 'C', 'C', 'O')], [9, 10, 11, 18, ('O', 'C', 'C', 'H')], [9, 10, 11, 19, ('O', 'C', 'C', 'H')], [10, 11, 12, 13, ('C', 'C', 'O', 'C')], [10, 11, 19, 22, ('C', 'C', 'H', 'C')], [16, 10, 11, 12, ('H', 'C', 'C', 'O')], [16, 10, 11, 18, ('H', 'C', 'C', 'H')]] self.assertEqual(len(self.topology.atoms), 44) self.assertEqual(len(self.topology.bonds), 50) self.assertEqual(len(self.topology.angles), 123) self.assertEqual(len(self.topology.dihedrals), 175) self.assertEqual(self.topology.atoms[17:27], atoms) self.assertEqual(self.topology.bonds[17:27], bonds) self.assertEqual(self.topology.angles[17:27], angles) self.assertEqual(self.topology.dihedrals[17:27], dihedrals) monomer_charges = [ -0.118700, -0.279200, -0.032600, -0.118700, -0.279200, -0.032600, 0.086100, 0.086100, 0.086100, 0.086100, 0.086100, 0.086100, 0.086100, 0.086100 ] monomer_atoms = [['C', 'C'], ['O', 'O'], ['C', 'C'], ['C', 'C'], ['O', 'O'], ['C', 'C'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H']] self.monomer.add_site_property("charge", monomer_charges) monomer_topology = Topology.from_molecule(self.monomer, tol=0.1) self.assertEqual(monomer_topology.atoms, monomer_atoms) self.assertEqual(monomer_topology.charges, monomer_charges)
def test_topology(self): atoms = [['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['C', 'C'], ['O', 'O'], ['C', 'C'], ['C', 'C'], ['O', 'O']] bonds = [[11, 19, ('C', 'H')], [12, 13, ('O', 'C')], [13, 20, ('C', 'H')], [13, 21, ('C', 'H')], [19, 22, ('H', 'C')], [22, 23, ('C', 'O')], [22, 29, ('C', 'H')], [23, 24, ('O', 'C')], [24, 25, ('C', 'C')], [24, 30, ('C', 'H')]] angles = [[8, 9, 10, ('C', 'O', 'C')], [9, 10, 11, ('O', 'C', 'C')], [9, 10, 16, ('O', 'C', 'H')], [9, 10, 17, ('O', 'C', 'H')], [11, 10, 16, ('C', 'C', 'H')], [11, 10, 17, ('C', 'C', 'H')], [10, 11, 12, ('C', 'C', 'O')], [10, 11, 18, ('C', 'C', 'H')], [10, 11, 19, ('C', 'C', 'H')], [16, 10, 17, ('H', 'C', 'H')]] dihedrals = [[8, 9, 10, 16, ('C', 'O', 'C', 'H')], [8, 9, 10, 17, ('C', 'O', 'C', 'H')], [15, 8, 9, 10, ('H', 'C', 'O', 'C')], [9, 10, 11, 12, ('O', 'C', 'C', 'O')], [9, 10, 11, 18, ('O', 'C', 'C', 'H')], [9, 10, 11, 19, ('O', 'C', 'C', 'H')], [10, 11, 12, 13, ('C', 'C', 'O', 'C')], [10, 11, 19, 22, ('C', 'C', 'H', 'C')], [16, 10, 11, 12, ('H', 'C', 'C', 'O')], [16, 10, 11, 18, ('H', 'C', 'C', 'H')]] self.assertEqual(len(self.topology.atoms), 44) self.assertEqual(len(self.topology.bonds), 50) self.assertEqual(len(self.topology.angles), 123) self.assertEqual(len(self.topology.dihedrals), 175) self.assertEqual(self.topology.atoms[17:27], atoms) self.assertEqual(self.topology.bonds[17:27], bonds) self.assertEqual(self.topology.angles[17:27], angles) self.assertEqual(self.topology.dihedrals[17:27], dihedrals) monomer_charges = [-0.118700, -0.279200, -0.032600, -0.118700, -0.279200, -0.032600, 0.086100, 0.086100, 0.086100, 0.086100,0.086100, 0.086100, 0.086100, 0.086100] monomer_atoms = [['C', 'C'], ['O', 'O'], ['C', 'C'], ['C', 'C'], ['O', 'O'], ['C', 'C'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H'], ['H', 'H']] self.monomer.add_site_property("charge", monomer_charges) monomer_topology = Topology.from_molecule(self.monomer, tol=0.1) self.assertEqual(monomer_topology.atoms, monomer_atoms) self.assertEqual(monomer_topology.charges, monomer_charges)
def setUp(self): # DMOE = Dimethoxyethane self.dmoe = Molecule.from_file(os.path.join(test_dir, "dmoe.xyz")) dmoe_charges = [-0.10, 0.09, 0.09, 0.09, -0.34, -0.01, 0.09, 0.09, -0.01, 0.09, 0.09, -0.34, -0.10, 0.09, 0.09, 0.09] self.dmoe.add_site_property("charge", dmoe_charges) ff_map = ["C3", "H3", "H3", "H3", "O", "C2", "H2", "H2", "C2", "H2", "H2", "O", "C3", "H3", "H3", "H3"] self.dmoe.add_site_property("ff_map", ff_map) self.topology = Topology.from_molecule(self.dmoe, ff_map="ff_map") self.forcefield = ForceField.from_file( os.path.join(test_dir, "ffmap_data.yaml")) self.box_size = [[0.0, 10], [0.0, 10], [0.0, 10]] self.lammps_ff_data = \ LammpsForceFieldData.from_forcefield_and_topology( [self.dmoe], [1], self.box_size, self.dmoe, self.forcefield, [self.topology])
def setUpClass(cls): atoms = OrderedDict([('hw', 'h'), ('ow', 'o')]) bonds = OrderedDict([((u'hw', u'ow'), [553.0, 0.957]), ((u'hw', u'hw'), [553.0, 1.513])]) angles = OrderedDict([((u'hw', u'ow', u'hw'), [0.0, 104.52])]) vdws = OrderedDict([(u'hw', [0.0, 0.0]), (u'ow', [1.7683, 0.1520])]) forcefield = ForceField(atoms, bonds, angles, vdws=vdws) h2o_coords = [[9.626, 6.787, 12.673], [9.626, 8.420, 12.673], [10.203, 7.604, 12.673]] h2o = Molecule(["H", "H", "O"], h2o_coords) # h2o, h-o, h-o, h=1, h=2, o=3 top_atoms = [['h', 'hw'], ['o', 'ow']] top_bonds = [[1, 3, ('hw', 'ow')], [2, 3, ('hw', 'ow')]] top_angles = [[1, 3, 2, ('hw', 'ow', 'hw')]] topology = Topology(top_atoms, top_bonds, top_angles) mols = [h2o] mols_number = [1] box_size = [[0.0, 10.0], [0.0, 10.0], [0.0, 10.0]] molecule = h2o topologies = [topology] cls.lammps_ff_data = LammpsForceFieldData.from_forcefield_and_topology( mols, mols_number, box_size, molecule, forcefield, topologies)
def setUpClass(cls): polymer = Molecule.from_file(os.path.join(test_dir, "polymer.xyz")) cls.topology = Topology.from_molecule(polymer, tol=0.1) cls.forcefield = ForceField.from_file(os.path.join(test_dir, "ff_data.yaml"))
def test_polymer_chain_topologies(self): topology_random = Topology.from_molecule(self.peo_polymer.molecule, tol=0.1) topology_linear = Topology.from_molecule(self.peo_polymer_linear.molecule, tol=0.1) self.assertNotEqual(topology_linear.bonds, topology_random.bonds) self.assertNotEqual(topology_linear.angles, topology_random.angles) self.assertNotEqual(topology_linear.dihedrals, topology_random.dihedrals)
def setUpClass(cls): polymer = Molecule.from_file(os.path.join(test_dir, "polymer.xyz")) cls.monomer = Molecule.from_file(os.path.join(test_dir, "monomer.xyz")) cls.topology = Topology.from_molecule(polymer, tol=0.1) cls.forcefield = ForceField.from_file( os.path.join(test_dir, "ff_data.yaml"))
def __init__(self, input_file, final_molecule, forcefield, box_size, topologies=None, constituent_molecules=None, mols_number=None, user_settings=None, ff_site_property=None, input_filename="lammps.in", data_filename="lammps.data", lammps_cmd="lammps", db_file=None, parents=None, log_filename="log.lammps", dump_filenames=None, name="LammpsFFFW", **kwargs): """ Write lammps input from forcefield and topology, run lammps, store results. Can be used with RunPackmol firework. Args: input_file (str): path to lammps input(or template) file. final_molecule (str/Molecule): either path to the moelcule of Molecule object. forcefield (ForceField): pymatgen.io.lammps.force_field.ForceField object box_size (list): list of list of low and high values for each dimension [[xlow, xhigh], ...] topologies ([Topology]): list of pymatgen.io.lammps.topology.Topology objects, one for each constituent molecule. constituent_molecules ([Molecule]): list of Molecule objects that make up the final_molecule mols_number (list): list of number of each constituent moelcule. user_settings (dict): ff_site_property (str): the site property used for forcefiled mapping input_filename (str): name of the input file to be written data_filename (str):name of the data file to be written lammps_cmd (str): lammps command run (without the input file) db_file (str): path to the db settings parents (list): list of Fireworks log_filename (str): lammps log file name dump_filenames (str): list of dump files name (str): firework name **kwargs: """ user_settings = user_settings or {} constituent_molecules = constituent_molecules or [final_molecule] mols_number = mols_number or [1] topologies = topologies or Topology.from_molecule( final_molecule, ff_map=ff_site_property) # one constituent molecule ==> no packmol usage. tasks = [CopyPackmolOutputs( calc_loc=True)] if mols_number != [1] else [] tasks.extend([ WriteInputFromForceFieldAndTopology( input_file=input_file, final_molecule_path=final_molecule, constituent_molecules=constituent_molecules, mols_number=mols_number, forcefield=forcefield, topologies=topologies, input_filename=input_filename, user_settings=user_settings, ff_site_property=ff_site_property, box_size=box_size), RunLammpsDirect(lammps_cmd=lammps_cmd, input_filename=input_filename), LammpsToDB(input_filename=input_filename, data_filename=data_filename, log_filename=log_filename, dump_filenames=dump_filenames, db_file=db_file, additional_fields={"task_label": name}) ]) super(LammpsForceFieldFW, self).__init__(tasks, parents=parents, name=name, **kwargs)