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))
Пример #2
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)
Пример #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:
            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)
 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))
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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()
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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)