Ejemplo n.º 1
0
    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])
Ejemplo n.º 2
0
    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])
Ejemplo n.º 3
0
    def from_file(cls, name, input_template, user_settings,
                  lammps_data=None, data_filename="in.data",
                  is_forcefield=False):
        """
        Returns LammpsInputSet from  input file template and input data.

        Args:
            name (str)
            input_template (string): path to the input template file.
            user_settings (dict): User lammps settings, the keys must
                correspond to the keys in the template.
            lammps_data (string/LammpsData/LammpsForceFieldData): path to the
                data file or an appropriate object
            data_filename (string): name of the the lammps data file.
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it. This is required only if lammps_data is
                a path to the data file instead of a data object.

        Returns:
            LammpsInputSet
        """
        user_settings["data_file"] = data_filename
        lammps_input = LammpsInput.from_file(input_template, user_settings)
        if isinstance(lammps_data, six.string_types):
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(lammps_data)
            else:
                lammps_data = LammpsData.from_file(lammps_data)
        return cls(name, lammps_input, lammps_data=lammps_data,
                   data_filename=data_filename)
Ejemplo n.º 4
0
    def from_file(name, filename, lammps_data=None, data_filename="in.data",
                  user_lammps_settings={}, is_forcefield=False):
        """
        Read in the input settings from json file as ordereddict.
        Note: with monty.serialization.loadfn the order of paramters in the
        json file is not preserved

        Args:
            filename (string): name of the file with the lamps control
                paramters
            lammps_data (string/LammpsData/LammpsForceFieldData): path to the
                data file or an appropriate object
            data_filename (string): name of the the lammps data file
            user_lammps_settings (dict): User lammps settings
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it. This is required only if lammps_data is
                a path to the data file instead of a data object

        Returns:
            DictLammpsInput
        """
        with open(filename) as f:
            config_dict = json.load(f, object_pairs_hook=OrderedDict)
        lammps_data = lammps_data
        if isinstance(lammps_data, six.string_types):
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(lammps_data)
            else:
                lammps_data = LammpsData.from_file(lammps_data)
        return DictLammpsInput(name, config_dict, lammps_data=lammps_data,
                               data_filename=data_filename,
                               user_lammps_settings=user_lammps_settings)
Ejemplo n.º 5
0
 def test_from_file(self):
     self.lammps_ff_data.write_data_file(
         os.path.join(test_dir, "lammps_ff_data.dat"))
     lammps_ff_data = LammpsForceFieldData.from_file(
         os.path.join(test_dir, "lammps_ff_data.dat"))
     np.testing.assert_almost_equal(lammps_ff_data.atomic_masses,
                                    self.lammps_ff_data.atomic_masses,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.pair_coeffs,
                                    self.lammps_ff_data.pair_coeffs,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.bond_coeffs,
                                    self.lammps_ff_data.bond_coeffs,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.angle_coeffs,
                                    self.lammps_ff_data.angle_coeffs,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.atoms_data,
                                    self.lammps_ff_data.atoms_data,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.bonds_data,
                                    self.lammps_ff_data.bonds_data,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.angles_data,
                                    self.lammps_ff_data.angles_data,
                                    decimal=10)
     self.assertEqual(str(lammps_ff_data), str(self.lammps_ff_data))
Ejemplo n.º 6
0
    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])
Ejemplo n.º 7
0
    def from_file(name, filename, data_filename=None, is_forcefield=False):
        """
        Read in the input settings from json file as ordereddict. Also
        reads in the datafile if provided.
        Note: with monty.serialization.loadfn the order of paramters in the
        json file is not preserved

        Args:
            filename (string): name of the file with the lamps control
                paramters
            data_filename (string): path to the data file
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it.

        Returns:
            DictLammpsInput
        """
        with open(filename) as f:
            config_dict = json.load(f, object_pairs_hook=OrderedDict)
        lammps_data = None
        if data_filename:
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(data_filename)
            else:
                lammps_data = LammpsData.from_file(data_filename)
        return DictLammpsInput(name, config_dict, lammps_data)
Ejemplo n.º 8
0
 def run_task(self, fw_spec):
     gaussian_file = fw_spec['prev_gaussian_freq']
     mol = fw_spec["molecule"]
     molecules = [mol]
     # list of gaussian files, one for each molecule type in molecules
     gaussian_files = [gaussian_file]
     # pack the molecules using packmol
     param_list = [{
         "number":
         100,
         "inside box": [-14.82, -14.82, -14.82, 14.82, 14.82, 14.82]
     }]
     pmr = PackmolRunner(molecules, param_list)
     packed_molecule = pmr.run()
     # lammps input
     input_filename = 'mol.inp'
     data_filename = 'mol.data'
     # generate amber force field data
     lammps_data = LammpsForceFieldData.from_amber(molecules,
                                                   param_list["number"],
                                                   param_list["inside box"],
                                                   packed_molecule,
                                                   gaussian_files)
     user_lammps_settings = {
         "fix1": "NPT all npt temp 298 298 100.0 iso 1.0 1.0 100.0",
         "fix2": "NVT all nvt temp 298 298 100.0"
     }
     lammps_input = NPTNVTLammpsInput(
         data_obj=lammps_data, user_lammps_settings=user_lammps_settings)
     lammps_input.write_input(input_filename, data_file=data_filename)
Ejemplo n.º 9
0
    def run_task(self, fw_spec):

        molecules = self["constituent_molecules"]
        mols_number = self["mols_number"]
        input_filename = self["input_filename"]
        forcefield = self["forcefield"]
        topologies = self["topologies"]

        user_settings = self.get("user_settings", {})
        data_filename = user_settings.get("data_file", "lammps.data")
        final_molecule = self["final_molecule"]
        if isinstance(final_molecule, six.string_types):
            final_molecule = Molecule.from_file(final_molecule)

        lammps_ff_data = LammpsForceFieldData.from_forcefield_and_topology(
            molecules, mols_number, self["box_size"], final_molecule,
            forcefield, topologies)

        lammps_input_set = LammpsInputSet.from_file(
            "forcefield",
            self["input_file"],
            user_settings=user_settings,
            lammps_data=lammps_ff_data,
            data_filename=data_filename,
            is_forcefield=True)

        lammps_input_set.write_input(input_filename, data_filename)
Ejemplo n.º 10
0
 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, pairs=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)
Ejemplo n.º 11
0
    def from_file(cls,
                  name,
                  input_template,
                  user_settings,
                  lammps_data=None,
                  data_filename="in.data",
                  is_forcefield=False):
        """
        Returns LammpsInputSet from  input file template and input data.

        Args:
            input_template (string): path to the input template file.
            user_settings (dict): User lammps settings, the keys must
                correspond to the keys in the template.
            lammps_data (string/LammpsData/LammpsForceFieldData): path to the
                data file or an appropriate object
            data_filename (string): name of the the lammps data file.
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it. This is required only if lammps_data is
                a path to the data file instead of a data object.

        Returns:
            LammpsInputSet
        """
        lammps_input = LammpsInput.from_file(input_template, user_settings)
        if isinstance(lammps_data, six.string_types):
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(lammps_data)
            else:
                lammps_data = LammpsData.from_file(lammps_data)
        return cls(name,
                   lammps_input,
                   lammps_data=lammps_data,
                   data_filename=data_filename)
Ejemplo n.º 12
0
    def from_file(name,
                  filename,
                  data_obj=None,
                  data_file=None,
                  is_forcefield=False):
        """
        Read in the input settings from json file as ordereddict. Also
        reads in the datafile if provided.
        Note: with monty.serialization.loadfn the order of paramters in the
        json file is not preserved

        Args:
            filename (string): name of the file with the lamps control
                paramters
            data_obj (LammpsData): LammpsData object
            data_file (string): name of the data file name
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it.

        Returns:
            DictLammpsInput
        """
        with open(filename) as f:
            config_dict = json.load(f, object_pairs_hook=OrderedDict)
        lammps_data = None
        if data_file:
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(data_file)
            else:
                lammps_data = LammpsData.from_file(data_file)
        if data_obj and isinstance(data_obj, LammpsData):
            lammps_data = data_obj
        return DictLammpsInput(name, config_dict, lammps_data)
Ejemplo n.º 13
0
 def test_from_file(self):
     self.lammps_ff_data.write_data_file(
         os.path.join(test_dir, "lammps_ff_data.dat"))
     lammps_ff_data = LammpsForceFieldData.from_file(
         os.path.join(test_dir, "lammps_ff_data.dat"))
     np.testing.assert_almost_equal(lammps_ff_data.atomic_masses,
                                    self.lammps_ff_data.atomic_masses,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.pair_coeffs,
                                    self.lammps_ff_data.pair_coeffs,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.bond_coeffs,
                                    self.lammps_ff_data.bond_coeffs,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.angle_coeffs,
                                    self.lammps_ff_data.angle_coeffs,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.atoms_data,
                                    self.lammps_ff_data.atoms_data,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.bonds_data,
                                    self.lammps_ff_data.bonds_data,
                                    decimal=10)
     np.testing.assert_almost_equal(lammps_ff_data.angles_data,
                                    self.lammps_ff_data.angles_data,
                                    decimal=10)
     self.assertEqual(str(lammps_ff_data), str(self.lammps_ff_data))
Ejemplo n.º 14
0
    def test_pair_coeffs(self):
        natoms, natom_types, atomic_masses_dict = \
            LammpsForceFieldData.get_basic_system_info(self.dmoe)

        # atom_types = list(atomic_masses_dict.keys())
        ans_atomtype_ids = [x[0] for x in atomic_masses_dict.values()]

        pair_coeffs = self.lammps_ff_data.pair_coeffs
        atomtype_ids = [x[0] for x in pair_coeffs]

        self.assertEqual(ans_atomtype_ids, atomtype_ids)
Ejemplo n.º 15
0
 def __init__(self, data_file, trajectory_file, log_file="log.lammps",
              is_forcefield=False):
     self.data_file = data_file
     self.trajectory_file = trajectory_file
     self.log_file = log_file
     self.lammps_log = LammpsLog(log_file)
     if is_forcefield:
         self.lammps_data = LammpsForceFieldData.from_file(data_file)
     else:
         self.lammps_data = LammpsData.from_file(data_file)
     self._set_mol_masses_and_charges()
     self._parse_trajectory()
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
    def test_system_info_with_ff_map(self):
        natoms, natom_types, atomic_masses_dict = \
            LammpsForceFieldData.get_basic_system_info(self.polymer_linear_ff_decorated)

        ans_atom_masses_dict = OrderedDict([('H2', [1, 1.00794]),
                                            ('H3', [2, 1.00794]),
                                            ('C2', [3, 12.0107]),
                                            ('C3', [4, 12.0107]),
                                            ('O', [5, 15.9994])])

        self.assertEqual(natoms, 51)
        self.assertEqual(natom_types, 5)
        self.assertEqual(atomic_masses_dict.keys(), ans_atom_masses_dict.keys())
        for k, v in atomic_masses_dict.items():
            self.assertEqual(ans_atom_masses_dict[k][1], v[1])
Ejemplo n.º 18
0
    def from_file(cls, name, filename, lammps_data=None, data_filename="in.data",
                  user_lammps_settings={}, is_forcefield=False):
        """
        Reads lammps style and JSON style input files putting the settings in an ordered dict (config_dict).
        Note: with monty.serialization.loadfn the order of paramters in the
        json file is not preserved

        Args:
            filename (string): name of the file with the lamps control
                paramters
            lammps_data (string/LammpsData/LammpsForceFieldData): path to the
                data file or an appropriate object
            data_filename (string): name of the the lammps data file
            user_lammps_settings (dict): User lammps settings
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it. This is required only if lammps_data is
                a path to the data file instead of a data object

        Returns:
            DictLammpsInput
        """
        try:
            with open(filename) as f:
                config_dict = json.load(f, object_pairs_hook=OrderedDict)
        except ValueError:
            with open(filename, 'r') as f:
                data = f.read().splitlines()
            config_dict = OrderedDict()
            for line in data:
                if line and not line.startswith("#"):
                    spt_line = (line.split(None, 1))
                    if spt_line[0] in config_dict:
                        if isinstance(config_dict[spt_line[0]], list):
                            config_dict[spt_line[0]].append(spt_line[1])
                        else:
                            config_dict[spt_line[0]] = [config_dict[spt_line[0]], spt_line[1]]
                    else:
                        config_dict[spt_line[0]] = spt_line[1]

        lammps_data = lammps_data
        if isinstance(lammps_data, six.string_types):
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(lammps_data)
            else:
                lammps_data = LammpsData.from_file(lammps_data)
        return cls(name, config_dict, lammps_data=lammps_data,
                               data_filename=data_filename,
                               user_lammps_settings=user_lammps_settings)
Ejemplo n.º 19
0
    def test_lammps_wflow(self):
        lammps_data = LammpsForceFieldData.from_file(self.data_file)
        log_filename = "peo.log"
        dump_filename = "peo.dump"
        dcd_traj_filename = "peo.dcd"
        timestep = 1  # in fmsec for 'real' units
        n_timesteps = 1000
        dump_freq = 50
        T = [300, 300, 100.0]  # start, end, damp
        P = [0, 0, 100.0]

        # override default settings read from the json file with these
        user_settings = {"log": log_filename,
                         "timestep": timestep,
                         "run": n_timesteps,
                         "pair_style": "buck/coul/cut 15.0",
                         "pair_coeff": ["1 1 2649.6 0.2674 27.22",
                                        "1 2 4320.0 0.2928 137.6",
                                        "1 3 14176.0 0.2563 104.0",
                                        "2 2 14976.0 0.3236 637.6",
                                        "2 3 33702.4 0.2796 503.0",
                                        "3 3 75844.8 0.2461 396.9"],
                         "thermo_style": "custom step time temp press pe ke etotal enthalpy fmax fnorm",
                         "fix": "NPT all npt temp {T[0]} {T[1]} {T[2]} iso {P[0]} {P[1]} {P[2]}".format(T=T, P=P),
                         "dump": [
                             "peodump all custom {} {} id type x y z ix iy iz mol".format(dump_freq, dump_filename),
                             "traj all dcd {} {}".format(dump_freq, dcd_traj_filename)]}

        if not LAMMPS_CMD:
            # fake run
            lammps_bin = "cp  ../../reference_files/peo.* ."
            dry_run = True
        else:
            lammps_bin = LAMMPS_CMD
            dry_run = False
        wf = wf_from_input_template(self.input_template, lammps_data, "npt.data", user_settings,
                                    is_forcefield=True, input_filename="lammps.inp", lammps_bin=lammps_bin,
                                    db_file=">>db_file<<", dry_run=dry_run)
        self.lp.add_wf(wf)
        # run
        rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")}))
        d = self._get_task_collection().find_one()
        self._check_run(d)
Ejemplo n.º 20
0
 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])
Ejemplo n.º 21
0
 def test_to_and_from_file(self):
     self.lammps_ff_data_1.write_data_file(
         os.path.join(test_dir,"lammps_ff_data.dat"))
     lammps_ff_data_2 = LammpsForceFieldData.from_file(
         os.path.join(test_dir,"lammps_ff_data.dat"))
     np.testing.assert_almost_equal(self.lammps_ff_data_1.bond_coeffs,
                      lammps_ff_data_2.bond_coeffs)
     np.testing.assert_almost_equal(self.lammps_ff_data_1.pair_coeffs,
                      lammps_ff_data_2.pair_coeffs)
     np.testing.assert_almost_equal(self.lammps_ff_data_1.angle_coeffs,
                      lammps_ff_data_2.angle_coeffs)
     np.testing.assert_almost_equal(self.lammps_ff_data_1.dihedral_coeffs,
                      lammps_ff_data_2.dihedral_coeffs)
     np.testing.assert_almost_equal(self.lammps_ff_data_1.atoms_data,
                                    lammps_ff_data_2.atoms_data, decimal=10)
     self.assertEqual(self.lammps_ff_data_1.bonds_data,
                      lammps_ff_data_2.bonds_data)
     self.assertEqual(self.lammps_ff_data_1.angles_data,
                      lammps_ff_data_2.angles_data)
     self.assertEqual(self.lammps_ff_data_1.dihedrals_data,
                      lammps_ff_data_2.dihedrals_data)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
    def from_file(name,
                  filename,
                  lammps_data=None,
                  data_filename="in.data",
                  user_lammps_settings={},
                  is_forcefield=False):
        """
        Read in the input settings from json file as ordereddict.
        Note: with monty.serialization.loadfn the order of paramters in the
        json file is not preserved

        Args:
            filename (string): name of the file with the lamps control
                paramters
            lammps_data (string/LammpsData/LammpsForceFieldData): path to the
                data file or an appropriate object
            data_filename (string): name of the the lammps data file
            user_lammps_settings (dict): User lammps settings
            is_forcefield (bool): whether the data file has forcefield and
                topology info in it. This is required only if lammps_data is
                a path to the data file instead of a data object

        Returns:
            DictLammpsInput
        """
        with open(filename) as f:
            config_dict = json.load(f, object_pairs_hook=OrderedDict)
        lammps_data = lammps_data
        if isinstance(lammps_data, six.string_types):
            if is_forcefield:
                lammps_data = LammpsForceFieldData.from_file(lammps_data)
            else:
                lammps_data = LammpsData.from_file(lammps_data)
        return DictLammpsInput(name,
                               config_dict,
                               lammps_data=lammps_data,
                               data_filename=data_filename,
                               user_lammps_settings=user_lammps_settings)