本文整理汇总了Python中chemlab.core.System类的典型用法代码示例。如果您正苦于以下问题:Python System类的具体用法?Python System怎么用?Python System使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了System类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_batch
def test_from_batch(self):
mols = self._make_molecules()
system = System()
with system.batch() as batch:
[batch.append(mol) for mol in mols]
self._assert_init(system)
示例2: test_reorder_molecules
def test_reorder_molecules(self):
mols = self._make_molecules()
system = System(mols)
system.bonds = np.array([[0, 1], [3, 5]])
# Reordering
system.reorder_molecules([1, 0, 2, 3])
assert_eqbonds(system.bonds, [[0, 2], [3, 4]])
示例3: test_remove_atoms
def test_remove_atoms(self):
# This will remove the first and last molecules
mols = self._make_molecules()
system = System(mols)
system.remove_atoms([0, 1, 11])
assert_eqbonds(system.bonds, [[0, 1], [0, 2], [3, 4], [3, 5]])
assert_npequal(system.type_array, np.array(["O", "H", "H", "O", "H", "H"], dtype="object"))
示例4: test_bond_orders
def test_bond_orders():
# Get a molecule with some bonds
wat = _make_water()
wat_o = wat.copy()
# 0,1 0,2
assert_npequal(wat.bond_orders, np.array([0, 0]))
# Remove a bond
wat.bonds = np.array([[0, 1]])
assert_npequal(wat.bond_orders, np.array([0]))
wat.bond_orders = np.array([2])
# Try with a system
s = System()
s.add(wat_o)
s.add(wat)
assert_npequal(s.bond_orders, np.array([0, 0, 2]))
s.reorder_molecules([1, 0])
# Bonds get sorted accordingly
assert_npequal(s.bond_orders, np.array([2, 0, 0]))
s.bonds = np.array([[0, 1], [0, 2], [3, 4], [3, 5]])
assert_npequal(s.bond_orders, np.array([2, 0, 0, 0]))
示例5: test_write_gromacs
def test_write_gromacs():
water = Molecule(
[
Atom("O", [0.0, 0.0, 0.0], export={"grotype": "OW"}),
Atom("H", [0.1, 0.0, 0.0], export={"grotype": "HW1"}),
Atom("H", [-0.03333, 0.09428, 0.0], export={"grotype": "HW2"}),
],
export={"groname": "SOL"},
)
sys = System.empty(200, 3 * 200, box_vectors=np.eye(3) * 2.0)
for i in range(200):
sys.add(water.copy())
df = datafile("/tmp/dummy.gro", mode="w")
df.write("system", sys)
with assert_raises(Exception):
df = datafile("/tmp/dummy.gro")
df.write("system", sys)
df = datafile("/tmp/dummy.gro")
sread = df.read("system")
assert all(sread.type_array == sys.type_array)
示例6: test_bond_orders
def test_bond_orders():
# Get a molecule with some bonds
wat = _make_water()
wat_o = wat.copy()
# 0,1 0,2
assert_npequal(wat.bond_orders, np.array([1, 1]))
# Remove a bond
wat.bonds = np.array([[0, 1]])
assert_npequal(wat.bond_orders, np.array([1]))
wat.bond_orders = np.array([2])
# Try with a system
s = System.empty(2, 6)
s.add(wat_o)
s.add(wat)
assert_npequal(s.bond_orders , np.array([1, 1, 2]))
s.reorder_molecules([1, 0]) # We don't actually sort bonds again
assert_npequal(s.bond_orders , np.array([1, 1, 2]))
s.bonds = np.array([[0, 1], [0, 2], [3, 4], [3, 5]])
assert_npequal(s.bond_orders, np.array([1, 1, 2, 1]))
示例7: test_merge_system
def test_merge_system():
# take a protein
from chemlab.io import datafile
from chemlab.graphics import display_system
from chemlab.db import ChemlabDB
water = ChemlabDB().get("molecule", "example.water")
prot = datafile("tests/data/3ZJE.pdb").read("system")
# Take a box of water
NWAT = 50000
bsize = 20.0
pos = np.random.random((NWAT, 3)) * bsize
wat = water.copy()
s = System.empty(NWAT, NWAT*3, box_vectors=np.eye(3)*bsize)
for i in range(NWAT):
wat.move_to(pos[i])
s.add(wat)
prot.r_array += 10
s = merge_systems(s, prot, 0.5)
display_system(s, 'ball-and-stick')
示例8: test_attributes
def test_attributes():
coords = [np.random.rand(10, 3) for i in range(10)]
t = np.arange(0, 10, 0.1)
traj = Trajectory(coords, t)
system = System.from_arrays(r_array=coords[0])
system.update(traj.at(1))
npeq_(system.r_array, coords[1])
示例9: test_bonds
def test_bonds():
# TODO: deprecate this shit
from chemlab.io import datafile
bz = datafile("tests/data/benzene.mol").read('molecule')
na = Molecule([Atom('O', [0.0, 0.0, 0.0]),
Atom('H', [0.0, 0.0, 0.0]),
Atom('H', [0.0, 0.0, 0.0]), ])
# Adding bonds
s = System()
with s.batch() as b:
b.append(bz)
assert_npequal(s.bonds, bz.bonds)
assert_npequal(bz.bond_orders, [1, 2, 2, 1, 1, 2])
assert_npequal(s.bond_orders, bz.bond_orders)
s.add(bz)
assert_npequal(s.type_array, ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
'C', 'C', 'C'])
eq_(s.dimensions['atom'], 12)
assert_npequal(s.bonds, np.concatenate((bz.bonds, bz.bonds + 7)))
# Reordering
s.bonds = np.array([[0, 1], [6, 8]])
s.reorder_molecules([1, 0])
assert_eqbonds(s.bonds, np.array([[6, 7], [0, 2]]))
# Selection
ss = subsystem_from_molecules(s, [1])
assert_npequal(ss.bonds, np.array([[0, 1]]))
示例10: test_local
def test_local():
db = ChemlabDB()
bz = db.get("molecule", "example.norbornene")
pre_string = bz.tojson()
db = LocalDB("/tmp/testdb/")
db.store("molecule", 'norbornene', bz, nowarn=True)
post_string = db.get('molecule', 'norbornene').tojson()
assert pre_string == post_string
# Do the same thing for a system of 3 norbornenes
s = System([bz.copy() for i in range(3)])
pre_string = s.tojson()
db.store("system", 'norbornene-3', s, nowarn=True)
post_string = db.get('system', 'norbornene-3').tojson()
assert pre_string == post_string
示例11: test_bonds
def test_bonds():
from chemlab.io import datafile
bz = datafile("tests/data/benzene.mol").read('molecule')
na = Molecule([Atom('Na', [0.0, 0.0, 0.0])])
# Adding bonds
s = System.empty(2, 2*bz.n_atoms)
s.add(bz)
assert_npequal(s.bonds, bz.bonds)
assert_npequal(bz.bond_orders, [1, 2, 2, 1, 1, 2])
assert_npequal(s.bond_orders, bz.bond_orders)
s.add(bz)
assert_npequal(s.bonds, np.concatenate((bz.bonds, bz.bonds + 6)))
#assert_npequal(s.bond_orders)
# Reordering
orig = np.array([[0, 1], [6, 8]])
s.bonds = orig
s.reorder_molecules([1, 0])
assert_npequal(s.bonds, np.array([[6, 7], [0, 2]]))
# This doesn't change the bond_ordering
# Selection
ss = subsystem_from_molecules(s, [1])
assert_npequal(ss.bonds, np.array([[0, 1]]))
import inspect
ss2 = System.from_arrays(**dict(inspect.getmembers(ss)))
ss2.r_array += 10.0
ms = merge_systems(ss, ss2)
assert_npequal(ms.bonds, np.array([[0, 1], [6, 7]]))
assert_npequal(ms.bond_orders, np.array([1, 1]))
# From_arrays
s = System.from_arrays(mol_indices=[0], bonds=bz.bonds, **bz.__dict__)
assert_npequal(s.bonds, bz.bonds)
assert_npequal(s.bond_orders, bz.bond_orders)
# Get molecule entry
# Test the bonds when they're 0
s.bonds = np.array([])
assert_equals(s.get_derived_molecule_array('formula'), 'C6')
示例12: test_local
def test_local():
db = ChemlabDB()
bz = db.get("molecule", "example.norbornene")
pre_dict = bz.to_dict()
db = LocalDB("/tmp/testdb/")
db.store("molecule", 'norbornene', bz, nowarn=True)
post_dict = db.get('molecule', 'norbornene').to_dict()
npeq_(pre_dict['r_array'], post_dict['r_array'])
# Do the same thing for a system of 3 norbornenes
s = System([bz.copy() for i in range(3)])
pre_dict = s.to_dict()
db.store("system", 'norbornene-3', s, nowarn=True)
post_dict = db.get('system', 'norbornene-3').to_dict()
npeq_(pre_dict['r_array'], post_dict['r_array'])
示例13: test_display
def test_display():
d = Display('povray')
s = System.from_arrays(type_array=['O', 'H', 'H'],
r_array=[[0.0, 0.0, 0.0], [0.15, 0.0, 0.0], [0.0, 0.15, 0.0]])
d.system(s)
s.r_array = s.r_array + 0.3
d.system(s, alpha=0.5)
d.render()
示例14: test_from_arrays
def test_from_arrays(self):
mols = self._make_molecules()
system = System.from_arrays(
r_array=np.concatenate([m.r_array for m in mols]),
type_array=np.concatenate([m.type_array for m in mols]),
bonds=np.concatenate([m.bonds + 3 * i for i, m in enumerate(mols)
]),
maps={
('atom', 'molecule'): [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
('bond', 'molecule'): [0, 0, 1, 1, 2, 2, 3, 3]
})
self._assert_init(system)
示例15: test_atom_type
def test_atom_type(self):
self.s = System.from_arrays(
type_array=["Cl", "Cl", "O", "H", "H", "O", "H", "H", "O", "H", "H", "Na", "Na"],
maps={("atom", "molecule"): [0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 6]},
)
idx = self.s.where(atom_type="O")
assert_npequal(
idx["atom"], [False, False, True, False, False, True, False, False, True, False, False, False, False]
)
assert_npequal(idx["molecule"], [False, False, True, True, True, False, False])
self.s = System.from_arrays(
type_array=["Cl", "Cl", "O", "H", "H", "O", "H", "H", "O", "H", "H", "Na", "Na"],
maps={("atom", "molecule"): [0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 6]},
)
idx = self.s.where(atom_type=["Na", "Cl"])
assert_npequal(
idx["atom"], [True, True, False, False, False, False, False, False, False, False, False, True, True]
)