本文整理汇总了Python中pymatgen.io.lammps.data.LammpsData.from_ff_and_topologies方法的典型用法代码示例。如果您正苦于以下问题:Python LammpsData.from_ff_and_topologies方法的具体用法?Python LammpsData.from_ff_and_topologies怎么用?Python LammpsData.from_ff_and_topologies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.io.lammps.data.LammpsData
的用法示例。
在下文中一共展示了LammpsData.from_ff_and_topologies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_ff_and_topologies
# 需要导入模块: from pymatgen.io.lammps.data import LammpsData [as 别名]
# 或者: from pymatgen.io.lammps.data.LammpsData import from_ff_and_topologies [as 别名]
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)