コード例 #1
0
ファイル: test_data.py プロジェクト: Tinaatucsd/pymatgen
 def setUpClass(cls):
     cls.peptide = LammpsBox(
         bounds=[[36.840194, 64.211560], [41.013691, 68.385058],
                 [29.768095, 57.139462]])
     cls.quartz = LammpsBox(bounds=[[0, 4.913400], [0, 4.255129],
                                    [0, 5.405200]],
                            tilt=[-2.456700, 0.0, 0.0])
コード例 #2
0
    def from_string(cls, string):
        """
        Constructor from string parsing.

        Args:
            string (str): Input string.

        """
        lines = string.split("\n")
        timestep = int(lines[1])
        natoms = int(lines[3])
        box_arr = np.loadtxt(StringIO("\n".join(lines[5:8])))
        bounds = box_arr[:, :2]
        tilt = None
        if "xy xz yz" in lines[4]:
            tilt = box_arr[:, 2]
            x = (0, tilt[0], tilt[1], tilt[0] + tilt[1])
            y = (0, tilt[2])
            bounds -= np.array([[min(x), max(x)], [min(y), max(y)], [0, 0]])
        box = LammpsBox(bounds, tilt)
        data_head = lines[8].replace("ITEM: ATOMS", "").split()
        data = pd.read_csv(StringIO("\n".join(lines[9:])),
                           names=data_head,
                           delim_whitespace=True)
        return cls(timestep, natoms, box, data)
コード例 #3
0
    def from_dict(cls, d):
        """
        Args:
            d (dict): Dict representation

        Returns:
            LammpsDump
        """
        items = {"timestep": d["timestep"], "natoms": d["natoms"]}
        items["box"] = LammpsBox.from_dict(d["box"])
        items["data"] = pd.read_json(d["data"], orient="split")
        return cls(**items)
コード例 #4
0
    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 = LammpsBox(
            [[-0.75694412, 44.165558], [0.38127473, 47.066074], [0.17900842, 44.193867]]
        )
        ice = LammpsData.from_ff_and_topologies(box=box, ff=ff, topologies=topologies)
        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(
            box=box, ff=broken_ff, topologies=[sample]
        )
        self.assertNotIn("Angles", ld_woangles.topology)
コード例 #5
0
ファイル: output.py プロジェクト: zbwang/pymatgen
 def _parse_timestep(self, dump):
     step = {}
     lines = dump.split("\n")
     step["timestep"] = int(lines[1])
     step["natoms"] = int(lines[3])
     step["atoms_data"] = np.loadtxt(StringIO("\n".join(lines[9:])),
                                     dtype=self.dtype)
     if self.parse_box:
         box_arr = np.loadtxt(StringIO("\n".join(lines[5:8])))
         bounds = box_arr[:, :2]
         tilt = None
         if "xy xz yz" in lines[4]:
             tilt = box_arr[:, 2]
             x = (0, tilt[0], tilt[1], tilt[0] + tilt[1])
             y = (0, tilt[2])
             bounds -= np.array([[min(x), max(x)], [min(y), max(y)],
                                 [0, 0]])
         step["box"] = LammpsBox(bounds, tilt)
     return step
コード例 #6
0
ファイル: outputs.py プロジェクト: ExpHP/pymatgen
 def from_dict(cls, d):
     items = {"timestep": d["timestep"], "natoms": d["natoms"]}
     items["box"] = LammpsBox.from_dict(d["box"])
     items["data"] = pd.read_json(d["data"], orient="split")
     return cls(**items)
コード例 #7
0
    def write_data_file(self, organism, job_dir_path, composition_space):
        """
        Writes the file (called in.data) containing the structure that LAMMPS
        reads.

        Args:
            organism: the Organism whose structure to write

            job_dir_path: path to the job directory (as a string) where the
                file will be written

            composition_space: the CompositionSpace of the search
        """

        # get xhi, yhi and zhi from the lattice vectors
        lattice_coords = organism.cell.lattice.matrix
        xhi = lattice_coords[0][0]
        yhi = lattice_coords[1][1]
        zhi = lattice_coords[2][2]
        box_bounds = [[0.0, xhi], [0.0, yhi], [0.0, zhi]]

        # get xy, xz and yz from the lattice vectors
        xy = lattice_coords[1][0]
        xz = lattice_coords[2][0]
        yz = lattice_coords[2][1]
        box_tilts = [xy, xz, yz]

        # make a LammpsBox object from the bounds and tilts
        lammps_box = LammpsBox(box_bounds, tilt=box_tilts)

        # parse the element symbols and atom_style from the lammps input
        # script, preserving the order in which the element symbols appear
        # TODO: not all formats give the element symbols at the end of the line
        #       containing the pair_coeff keyword. Find a better way.
        elements_dict = collections.OrderedDict()
        num_elements = len(composition_space.get_all_elements())

        is_single_element = (num_elements == 1)
        if is_single_element:
            single_element = composition_space.get_all_elements()
            elements_dict[single_element[0].symbol] = single_element[0]

        with open(self.input_script, 'r') as f:
            lines = f.readlines()
            for line in lines:
                if 'atom_style' in line:
                    atom_style_in_script = line.split()[1]
                elif not is_single_element and 'pair_coeff' in line:
                    element_symbols = line.split()[-1 * num_elements:]

        if not is_single_element:
            for symbol in element_symbols:
                elements_dict[symbol] = Element(symbol)

        # make a LammpsData object and use it write the in.data file
        force_field = ForceField(elements_dict.items())
        topology = Topology(organism.cell.sites)
        lammps_data = LammpsData.from_ff_and_topologies(
            lammps_box,
            force_field, [topology],
            atom_style=atom_style_in_script)
        lammps_data.write_file(job_dir_path + '/in.data')
コード例 #8
0
ファイル: outputs.py プロジェクト: JMPriest/test_matminer
 def from_dict(cls, d):
     items = {"timestep": d["timestep"], "natoms": d["natoms"]}
     items["box"] = LammpsBox.from_dict(d["box"])
     items["data"] = pd.read_json(d["data"], orient="split")
     return cls(**items)