当前位置: 首页>>代码示例>>Python>>正文


Python data.LammpsData类代码示例

本文整理汇总了Python中pymatgen.io.lammps.data.LammpsData的典型用法代码示例。如果您正苦于以下问题:Python LammpsData类的具体用法?Python LammpsData怎么用?Python LammpsData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LammpsData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_structure

    def test_structure(self):
        quartz = self.quartz.structure
        np.testing.assert_array_equal(quartz.lattice.matrix,
                                      [[4.913400, 0, 0],
                                       [-2.456700, 4.255129, 0],
                                       [0, 0, 5.405200]])
        self.assertEqual(quartz.formula, "Si3 O6")
        self.assertNotIn("molecule-ID", self.quartz.atoms.columns)

        ethane = self.ethane.structure
        np.testing.assert_array_equal(ethane.lattice.matrix,
                                      np.diag([10.0] * 3))
        lbounds = np.array(self.ethane.box.bounds)[:, 0]
        coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds
        np.testing.assert_array_equal(ethane.cart_coords, coords)
        np.testing.assert_array_equal(ethane.site_properties["charge"],
                                      self.ethane.atoms["q"])
        tatb = self.tatb.structure
        frac_coords = tatb.frac_coords[381]
        real_frac_coords = frac_coords - np.floor(frac_coords)
        np.testing.assert_array_almost_equal(real_frac_coords,
                                             [0.01553397,
                                              0.71487872,
                                              0.14134139])

        co = Structure.from_spacegroup(194,
                                       Lattice.hexagonal(2.50078, 4.03333),
                                       ["Co"], [[1/3, 2/3, 1/4]])
        ld_co = LammpsData.from_structure(co)
        self.assertEqual(ld_co.structure.composition.reduced_formula, "Co")
        ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804),
                                       ["Ni"], [[0, 0, 0]])
        ld_ni = LammpsData.from_structure(ni)
        self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
开发者ID:ExpHP,项目名称:pymatgen,代码行数:34,代码来源:test_data.py

示例2: from_file

    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)
开发者ID:cchenae,项目名称:pymatgen,代码行数:26,代码来源:input.py

示例3: from_file

    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)
开发者ID:adozier,项目名称:pymatgen,代码行数:32,代码来源:input.py

示例4: from_file

    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)
开发者ID:matk86,项目名称:pymatgen,代码行数:30,代码来源:sets.py

示例5: setUpClass

 def setUpClass(cls):
     h2o_coords = [[9.626, 6.787, 12.673],
                   [9.626, 8.420, 12.673],
                   [10.203, 7.604, 12.673]]
     molecule = Molecule(["H", "H", "O"], h2o_coords)
     box_size = [[0.0, 10.0], [0.0, 10.0], [0.0, 10.0]]
     cls.lammps_data = LammpsData.from_structure(molecule, box_size)
开发者ID:PDoakORNL,项目名称:pymatgen,代码行数:7,代码来源:test_lammps_data.py

示例6: test_from_ff_and_topologies

    def test_from_ff_and_topologies(self):
        mass = OrderedDict()
        mass["H"] = 1.0079401
        mass["O"] = 15.999400
        nonbond_coeffs = [[0.00774378, 0.98], [0.1502629, 3.1169]]
        topo_coeffs = {"Bond Coeffs": [{"coeffs": [176.864, 0.9611],
                                        "types": [("H", "O")]}],
                       "Angle Coeffs": [{"coeffs": [42.1845, 109.4712],
                                         "types": [("H", "O", "H")]}]}
        ff = ForceField(mass.items(), nonbond_coeffs, topo_coeffs)
        with gzip.open(os.path.join(test_dir, "topologies_ice.json.gz")) as f:
            topo_dicts = json.load(f)
        topologies = [Topology.from_dict(d) for d in topo_dicts]
        box_bounds = [[-0.75694412, 44.165558],
                      [0.38127473, 47.066074],
                      [0.17900842, 44.193867]]
        ice = LammpsData.from_ff_and_topologies(ff=ff, topologies=topologies,
                                                box_bounds=box_bounds)
        atoms = ice.atoms
        bonds = ice.topology["Bonds"]
        angles = ice.topology["Angles"]
        np.testing.assert_array_equal(atoms.index.values,
                                      np.arange(1, len(atoms) + 1))
        np.testing.assert_array_equal(bonds.index.values,
                                      np.arange(1, len(bonds) + 1))
        np.testing.assert_array_equal(angles.index.values,
                                      np.arange(1, len(angles) + 1))

        i = random.randint(0, len(topologies) - 1)
        sample = topologies[i]
        in_atoms = ice.atoms[ice.atoms["molecule-ID"] == i + 1]
        np.testing.assert_array_equal(in_atoms.index.values,
                                      np.arange(3 * i + 1, 3 * i + 4))
        np.testing.assert_array_equal(in_atoms["type"].values, [2, 1, 1])
        np.testing.assert_array_equal(in_atoms["q"].values, sample.charges)
        np.testing.assert_array_equal(in_atoms[["x", "y", "z"]].values,
                                      sample.sites.cart_coords)
        broken_topo_coeffs = {"Bond Coeffs": [{"coeffs": [176.864, 0.9611],
                                               "types": [("H", "O")]}],
                              "Angle Coeffs": [{"coeffs": [42.1845, 109.4712],
                                                "types": [("H", "H", "H")]}]}
        broken_ff = ForceField(mass.items(), nonbond_coeffs,
                               broken_topo_coeffs)
        ld_woangles = LammpsData.from_ff_and_topologies(ff=broken_ff,
                                                        topologies=[sample],
                                                        box_bounds=box_bounds)
        self.assertNotIn("Angles", ld_woangles.topology)
开发者ID:czhengsci,项目名称:pymatgen,代码行数:47,代码来源:test_data.py

示例7: test_write_file

 def test_write_file(self):
     filename1 = "test1.data"
     self.ethane.write_file(filename=filename1)
     c2h6 = LammpsData.from_file(filename1)
     pd.testing.assert_frame_equal(c2h6.masses, self.ethane.masses)
     pd.testing.assert_frame_equal(c2h6.atoms, self.ethane.atoms)
     ff_kw = random.sample(self.ethane.force_field.keys(), 1)[0]
     pd.testing.assert_frame_equal(c2h6.force_field[ff_kw],
                                   self.ethane.force_field[ff_kw], ff_kw)
     topo_kw = random.sample(self.ethane.topology.keys(), 1)[0]
     pd.testing.assert_frame_equal(c2h6.topology[topo_kw],
                                   self.ethane.topology[topo_kw], topo_kw)
     filename2 = "test2.data"
     self.virus.write_file(filename=filename2)
     v = LammpsData.from_file(filename2, atom_style="angle")
     pd.testing.assert_frame_equal(v.force_field["PairIJ Coeffs"],
                                   self.virus.force_field["PairIJ Coeffs"])
开发者ID:ExpHP,项目名称:pymatgen,代码行数:17,代码来源:test_data.py

示例8: __init__

 def __init__(self, data_file, trajectory_file, log_file="log.lammps"):
     self.data_file = os.path.abspath(data_file)
     self.trajectory_file = os.path.abspath(trajectory_file)
     self.log_file = os.path.abspath(log_file)
     self.log = LammpsLog(log_file)
     self.lammps_data = LammpsData.from_file(self.data_file)
     self._set_mol_masses_and_charges()
     self._parse_trajectory()
开发者ID:mbkumar,项目名称:pymatgen,代码行数:8,代码来源:output.py

示例9: __init__

 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()
开发者ID:adozier,项目名称:pymatgen,代码行数:12,代码来源:output.py

示例10: test_md

    def test_md(self):
        s = Structure.from_spacegroup(225, Lattice.cubic(3.62126),
                                      ["Cu"], [[0, 0, 0]])
        ld = LammpsData.from_structure(s, atom_style="atomic")
        ff = "\n".join(["pair_style eam", "pair_coeff * * Cu_u3.eam"])
        md = LammpsRun.md(data=ld, force_field=ff, temperature=1600.0,
                          nsteps=10000)
        md.write_inputs(output_dir="md")
        with open(os.path.join("md", "in.md")) as f:
            md_script = f.read()
        script_string = """# Sample input script template for MD

# Initialization

units           metal
atom_style      atomic

# Atom definition

read_data       md.data
#read_restart    md.restart

# Force field settings (consult official document for detailed formats)

pair_style eam
pair_coeff * * Cu_u3.eam

# Create velocities
velocity        all create 1600.0 142857 mom yes rot yes dist gaussian

# Ensemble constraints
#fix             1 all nve
fix             1 all nvt temp 1600.0 1600.0 0.1
#fix             1 all npt temp 1600.0 1600.0 0.1 iso $pressure $pressure 1.0

# Various operations within timestepping
#fix             ...
#compute         ...

# Output settings
#thermo_style    custom ...  # control the thermo data type to output
thermo          100  # output thermo data every N steps
#dump            1 all atom 100 traj.*.gz  # dump a snapshot every 100 steps

# Actions
run             10000
"""
        self.assertEqual(md_script, script_string)
        self.assertTrue(os.path.exists(os.path.join("md", "md.data")))
开发者ID:ExpHP,项目名称:pymatgen,代码行数:49,代码来源:test_inputs.py

示例11: test_write_lammps_inputs

    def test_write_lammps_inputs(self):
        # script template
        with open(os.path.join(test_dir, "kappa.txt")) as f:
            kappa_template = f.read()
        kappa_settings = {"method": "heat"}
        write_lammps_inputs(output_dir="heat", script_template=kappa_template,
                            settings=kappa_settings)
        with open(os.path.join("heat", "in.lammps")) as f:
            kappa_script = f.read()
        fix_hot = re.search(r"fix\s+hot\s+all\s+([^\s]+)\s+", kappa_script)
        # placeholders supposed to be filled
        self.assertEqual(fix_hot.group(1), "heat")
        fix_cold = re.search(r"fix\s+cold\s+all\s+([^\s]+)\s+", kappa_script)
        self.assertEqual(fix_cold.group(1), "heat")
        lattice = re.search(r"lattice\s+fcc\s+(.*)\n", kappa_script)
        # parentheses not supposed to be filled
        self.assertEqual(lattice.group(1), "${rho}")
        pair_style = re.search(r"pair_style\slj/cut\s+(.*)\n", kappa_script)
        self.assertEqual(pair_style.group(1), "${rc}")

        with open(os.path.join(test_dir, "in.peptide")) as f:
            peptide_script = f.read()
        # copy data file
        src = os.path.join(test_dir, "data.quartz")
        write_lammps_inputs(output_dir="path", script_template=peptide_script,
                            data=src)
        dst = os.path.join("path", "data.peptide")
        self.assertTrue(filecmp.cmp(src, dst, shallow=False))
        # write data file from obj
        obj = LammpsData.from_file(src, atom_style="atomic")
        write_lammps_inputs(output_dir="obj", script_template=peptide_script,
                            data=obj)
        obj_read = LammpsData.from_file(os.path.join("obj", "data.peptide"),
                                        atom_style="atomic")
        pd.testing.assert_frame_equal(obj_read.masses, obj.masses)
        pd.testing.assert_frame_equal(obj_read.atoms, obj.atoms)
开发者ID:ExpHP,项目名称:pymatgen,代码行数:36,代码来源:test_inputs.py

示例12: from_structure

    def from_structure(cls, structure, input_template, user_settings,
                       data_filename="in.data", name="basic"):
        """
        Returns inputset from structure

        Args:
            structure (Structure/Molecule):
            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.
            data_filename (string): name of the the lammps data file.

        Returns:
            LammpsInputSet
        """

        lammps_data = LammpsData.from_structure(structure)
        return cls.from_file(name, input_template, user_settings,
                             lammps_data=lammps_data, data_filename=data_filename)
开发者ID:matk86,项目名称:pymatgen,代码行数:19,代码来源:sets.py

示例13: test_json_dict

 def test_json_dict(self):
     encoded = json.dumps(self.ethane.as_dict())
     decoded = json.loads(encoded)
     c2h6 = LammpsData.from_dict(decoded)
     pd.testing.assert_frame_equal(c2h6.masses, self.ethane.masses)
     pd.testing.assert_frame_equal(c2h6.atoms, self.ethane.atoms)
     ff = self.ethane.force_field
     key, target_df = random.sample(ff.items(), 1)[0]
     self.assertIsNone(
         pd.testing.assert_frame_equal(c2h6.force_field[key], target_df,
                                       check_dtype=False),
         key
     )
     topo = self.ethane.topology
     key, target_df = random.sample(topo.items(), 1)[0]
     self.assertIsNone(
         pd.testing.assert_frame_equal(c2h6.topology[key], target_df),
         key
     )
开发者ID:ExpHP,项目名称:pymatgen,代码行数:19,代码来源:test_data.py

示例14: test_from_structure

 def test_from_structure(self):
     latt = Lattice.monoclinic(9.78746, 4.75058, 8.95892, 115.9693)
     structure = Structure.from_spacegroup(15, latt, ["Os", "O", "O"],
                                           [[0, 0.25583, 0.75],
                                            [0.11146, 0.46611, 0.91631],
                                            [0.11445, 0.04564, 0.69518]])
     velocities = np.random.randn(20, 3) * 0.1
     structure.add_site_property("velocities", velocities)
     ld = LammpsData.from_structure(structure=structure,
                                    ff_elements=["O", "Os", "Na"])
     i = random.randint(0, 19)
     a = latt.matrix[0]
     va = velocities[i].dot(a) / np.linalg.norm(a)
     self.assertAlmostEqual(va, ld.velocities.loc[i + 1, "vx"])
     self.assertAlmostEqual(velocities[i, 1],
                            ld.velocities.loc[i + 1, "vy"])
     np.testing.assert_array_almost_equal(ld.masses["mass"],
                                          [22.989769, 190.23, 15.9994])
     np.testing.assert_array_equal(ld.atoms["type"], [2] * 4 + [3] * 16)
开发者ID:ExpHP,项目名称:pymatgen,代码行数:19,代码来源:test_data.py

示例15: from_file

    def from_file(cls, name, input_template, user_settings,
                  lammps_data=None, data_filename="in.data"):
        """
        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): path to the
                data file or an appropriate object
            data_filename (string): name of the the lammps data file.

        Returns:
            LammpsInputSet
        """
        user_settings["data_file"] = data_filename
        lammps_input = LammpsInput.from_file(input_template, user_settings)
        if isinstance(lammps_data, six.string_types):
            lammps_data = LammpsData.from_file(lammps_data)
        return cls(name, lammps_input, lammps_data=lammps_data,
                   data_filename=data_filename)
开发者ID:czhengsci,项目名称:pymatgen,代码行数:23,代码来源:sets.py


注:本文中的pymatgen.io.lammps.data.LammpsData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。