本文整理汇总了Python中mbuild.clone函数的典型用法代码示例。如果您正苦于以下问题:Python clone函数的具体用法?Python clone怎么用?Python clone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
def apply(self, compound, orientation='', compound_port=''):
"""Arrange copies of a Compound as specified by the Pattern.
Parameters
----------
compound
orientation
Returns
-------
"""
compounds = list()
if self.orientations.get(orientation):
for port in self.orientations[orientation]:
new_compound = clone(compound)
new_port = new_compound.labels[compound_port]
equivalence_transform(new_compound, new_port['up'], port['up'])
compounds.append(new_compound)
else:
for point in self.points:
new_compound = clone(compound)
translate(new_compound, point)
compounds.append(new_compound)
return compounds
示例2: benzene_from_parts
def benzene_from_parts(self):
ch = mb.load(get_fn('ch.mol2'))
ch.name = 'CH'
mb.translate(ch, -ch[0].pos)
ch.add(mb.Port(anchor=ch[0], separation=0.07), 'a')
mb.rotate_around_z(ch['a'], 120.0 * (np.pi/180.0))
ch.add(mb.Port(anchor=ch[0], separation=0.07), 'b')
mb.rotate_around_z(ch['b'], -120.0 * (np.pi/180.0))
ch_copy = mb.clone(ch)
benzene = mb.Compound(name='Benzene')
benzene.add(ch)
current = ch
for _ in range(5):
ch_new = mb.clone(ch_copy)
mb.force_overlap(move_this=ch_new,
from_positions=ch_new['a'],
to_positions=current['b'])
current = ch_new
benzene.add(ch_new)
carbons = [p for p in benzene.particles_by_name('C')]
benzene.add_bond((carbons[0],carbons[-1]))
return benzene
示例3: apply_to_compound
def apply_to_compound(self, guest, guest_port_name='down', host=None,
backfill=None, backfill_port_name='up'):
"""Attach copies of a guest Compound to Ports on a host Compound.
Parameters
----------
guest
guest_port_name
host
backfill
backfill_port_name
Returns
-------
"""
n_ports = len(host.available_ports())
assert n_ports >= self.points.shape[0], "Not enough ports for pattern."
assert_port_exists(guest_port_name, guest)
box = host.boundingbox
pattern = self.points * box.lengths + box.mins
port_positions = np.empty(shape=(n_ports, 3))
port_list = list()
for port_idx, port in enumerate(host.available_ports()):
port_positions[port_idx, :] = port['up']['middle'].pos
port_list.append(port)
used_ports = set() # Keep track of used ports for backfilling.
guests = []
for point in pattern:
closest_point_idx = np.argmin(host.min_periodic_distance(point, port_positions))
closest_port = port_list[closest_point_idx]
used_ports.add(closest_port)
# Attach the guest to the closest port.
new_guest = clone(guest)
equivalence_transform(new_guest, new_guest.labels[guest_port_name], closest_port)
guests.append(new_guest)
# Move the port as far away as possible (simpler than removing it).
# There may well be a more elegant/efficient way of doing this.
port_positions[closest_point_idx, :] = np.array([np.inf, np.inf, np.inf])
backfills = []
if backfill:
assert_port_exists(backfill_port_name, backfill)
# Attach the backfilling Compound to unused ports.
for port in port_list:
if port not in used_ports:
new_backfill = clone(backfill)
# Might make sense to have a backfill_port_name option...
equivalence_transform(
new_backfill, new_backfill.labels[backfill_port_name], port)
backfills.append(new_backfill)
return guests, backfills
示例4: test_rigid_with_subcompounds5
def test_rigid_with_subcompounds5(self, rigid_benzene):
rigid_benzene2 = mb.clone(rigid_benzene)
double = mb.Compound(subcompounds=[rigid_benzene, rigid_benzene2])
double2 = mb.clone(double)
compound = mb.Compound(subcompounds=[double, double2])
assert compound.max_rigid_id is 3
assert len(list(compound.rigid_particles())) == 48
for rigid_id in range(4):
assert len(list(compound.rigid_particles(rigid_id=rigid_id))) == 12
示例5: test_resnames_mdtraj
def test_resnames_mdtraj(self, h2o, ethane):
system = mb.Compound([h2o, mb.clone(h2o), ethane])
traj = system.to_trajectory(residues=['Ethane', 'H2O'])
residues = list(traj.top.residues)
assert traj.n_residues == 3
assert residues[0].name == 'H2O'
assert residues[1].name == 'H2O'
assert residues[2].name == 'Ethane'
traj = system.to_trajectory(residues='Ethane')
residues = list(traj.top.residues)
assert traj.n_residues == 2
assert residues[0].name == 'RES'
assert residues[1].name == 'Ethane'
traj = system.to_trajectory(residues=['Ethane'])
residues = list(traj.top.residues)
assert traj.n_residues == 2
assert residues[0].name == 'RES'
assert residues[1].name == 'Ethane'
traj = system.to_trajectory()
residues = list(traj.top.residues)
assert traj.n_residues == 1
assert residues[0].name == 'RES'
示例6: __init__
def __init__(self, proto, port_labels=("up", "down"), n=2):
if n < 1:
raise Exception('n must be 1 or more')
super(Polymer, self).__init__()
for label in port_labels:
assert_port_exists(label, proto)
last_part = None
for _ in range(n):
this_part = clone(proto)
self.add(this_part, 'monomer[$]')
if last_part is None:
first_part = this_part
else:
# Transform this part, such that it's bottom port is rotated
# and translated to the last part's top port.
equivalence_transform(this_part, this_part.labels[port_labels[1]],
last_part.labels[port_labels[0]])
last_part = this_part
# Hoist the last part's top port to be the top port of the polymer.
self.add(last_part.labels[port_labels[0]], port_labels[0], containment=False)
# Hoist the first part's bottom port to be the bottom port of the polymer.
self.add(first_part.labels[port_labels[1]], port_labels[1], containment=False)
示例7: test_different_translate_tos_not_origin
def test_different_translate_tos_not_origin(self, methane):
shifted = mb.clone(methane)
np.random.seed(0)
point = np.random.rand(3)
shifted.translate_to(point)
x = mb.coordinate_transform._translate_to(methane.xyz, point)
assert np.array_equal(shifted.xyz, x)
示例8: test_create_semi_rigid_bodies_hierarchy
def test_create_semi_rigid_bodies_hierarchy(self, benzene_from_parts):
n_benzenes = 10
filled = mb.fill_box(benzene_from_parts,
n_compounds=n_benzenes,
box=[0, 0, 0, 4, 4, 4])
filled.name = 'Benzene box'
filled2 = mb.clone(filled)
compound = mb.Compound(subcompounds=[filled, filled2])
compound.label_rigid_bodies(discrete_bodies='Benzene box')
assert compound.max_rigid_id == 1
assert filled.max_rigid_id == 0
assert filled2.max_rigid_id == 1
assert len(list(compound.rigid_particles())) == n_benzenes * 2 * 12
compound.unlabel_rigid_bodies()
compound.label_rigid_bodies(discrete_bodies='Benzene', rigid_particles='C')
assert compound.max_rigid_id == (n_benzenes*2) - 1
assert filled.max_rigid_id == n_benzenes - 1
assert filled2.max_rigid_id == (n_benzenes*2) - 1
assert len(list(compound.rigid_particles())) == n_benzenes * 2 * 6
assert len(list(filled.rigid_particles())) == n_benzenes * 6
assert len(list(filled2.rigid_particles())) == n_benzenes * 6
compound.unlabel_rigid_bodies()
compound.label_rigid_bodies(discrete_bodies='CH')
assert compound.max_rigid_id == (n_benzenes*2*6) - 1
assert filled.max_rigid_id == (n_benzenes*6) - 1
assert filled2.max_rigid_id == (n_benzenes*2*6) - 1
assert len(list(compound.rigid_particles())) == n_benzenes * 2 * 12
assert len(list(filled.rigid_particles())) == n_benzenes * 12
assert len(list(filled2.rigid_particles())) == n_benzenes * 12
示例9: _connect_and_reconnect
def _connect_and_reconnect(chf, bond_vector):
first = mb.clone(chf)
second = mb.clone(chf)
first.add(mb.Port(anchor=first[0], orientation=bond_vector,
separation=0.075), label='up')
second.add(mb.Port(anchor=second[0], orientation=-bond_vector,
separation=0.075), label='down')
c2h2f2 = mb.Compound(subcompounds=(first, second))
mb.force_overlap(first, first['up'], second['down'])
fccf_dihedral_init = calc_dihedral(first[2].pos, first[0].pos,
second[0].pos, second[2].pos)
c2h2f2.remove_bond((first[0], second[0]))
mb.force_overlap(first, first['port[0]'], second['port[0]'])
fccf_dihedral_final = calc_dihedral(first[2].pos, first[0].pos,
second[0].pos, second[2].pos)
return fccf_dihedral_init, fccf_dihedral_final
示例10: test_resnames_parmed
def test_resnames_parmed(self, h2o, ethane):
system = mb.Compound([h2o, mb.clone(h2o), ethane])
struct = system.to_parmed(residues=['Ethane', 'H2O'])
assert len(struct.residues) == 3
assert struct.residues[0].name == 'H2O'
assert struct.residues[1].name == 'H2O'
assert struct.residues[2].name == 'Ethane'
assert sum(len(res.atoms) for res in struct.residues) == len(struct.atoms)
struct = system.to_parmed(residues=['Ethane', 'H2O'])
assert len(struct.residues) == 3
assert struct.residues[0].name == 'H2O'
assert struct.residues[1].name == 'H2O'
assert struct.residues[2].name == 'Ethane'
assert sum(len(res.atoms) for res in struct.residues) == len(struct.atoms)
struct = system.to_parmed(residues='Ethane')
assert len(struct.residues) == 2
assert struct.residues[0].name == 'RES'
assert struct.residues[1].name == 'Ethane'
assert sum(len(res.atoms) for res in struct.residues) == len(struct.atoms)
struct = system.to_parmed()
assert len(struct.residues) == 1
assert struct.residues[0].name == 'RES'
assert sum(len(res.atoms) for res in struct.residues) == len(struct.atoms)
示例11: test_bond_graph
def test_bond_graph(self, ch3):
compound = mb.Compound()
compound.add(ch3)
assert compound.n_bonds == 3
assert all(compound.bond_graph.has_node(particle)
for particle in ch3.particles())
ch3_nobonds = mb.clone(ch3)
for bond in ch3_nobonds.bonds():
ch3_nobonds.remove_bond(bond)
compound.add(ch3_nobonds)
assert compound.n_bonds == 3
assert not any(compound.bond_graph.has_node(particle)
for particle in ch3_nobonds.particles())
carbons = list(compound.particles_by_name('C'))
compound.add_bond((carbons[0], carbons[1]))
assert compound.n_bonds == 4
assert all(compound.bond_graph.has_node(particle)
for particle in carbons)
assert any(compound.bond_graph.has_node(particle)
for particle in ch3_nobonds.particles())
compound.remove_bond((carbons[0], carbons[1]))
assert not any(compound.bond_graph.has_node(particle)
for particle in ch3_nobonds.particles())
示例12: solvate
def solvate(solute, solvent, n_solvent, box, overlap=0.2, seed=12345):
"""Solvate a compound in a box of solvent using packmol.
Parameters
----------
solute : mb.Compound
solvent : mb.Compound
n_solvent : int
box : mb.Box
overlap : float
Returns
-------
solvated : mb.Compound
"""
if not PACKMOL:
raise IOError("Packmol not found")
box = _validate_box(box)
if not isinstance(solvent, (list, set)):
solvent = [solvent]
if not isinstance(n_solvent, (list, set)):
n_solvent = [n_solvent]
# In angstroms for packmol.
box_mins = box.mins * 10
box_maxs = box.maxs * 10
overlap *= 10
center_solute = (box_maxs + box_mins) / 2
# Build the input file for each compound and call packmol.
solvated_pdb = tempfile.mkstemp(suffix='.pdb')[1]
solute_pdb = tempfile.mkstemp(suffix='.pdb')[1]
solute.save(solute_pdb, overwrite=True)
input_text = (PACKMOL_HEADER.format(overlap, solvated_pdb, seed) +
PACKMOL_SOLUTE.format(solute_pdb, *center_solute))
for solv, m_solvent in zip(solvent, n_solvent):
m_solvent = int(m_solvent)
solvent_pdb = tempfile.mkstemp(suffix='.pdb')[1]
solv.save(solvent_pdb, overwrite=True)
input_text += PACKMOL_BOX.format(solvent_pdb, m_solvent,
box_mins[0], box_mins[1], box_mins[2],
box_maxs[0], box_maxs[1], box_maxs[2])
proc = Popen(PACKMOL, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
out, err = proc.communicate(input=input_text)
if err:
_packmol_error(out, err)
# Create the topology and update the coordinates.
solvated = Compound()
solvated.add(solute)
for solv, m_solvent in zip(solvent, n_solvent):
for _ in range(m_solvent):
solvated.add(clone(solv))
solvated.update_coordinates(solvated_pdb)
return solvated
示例13: test_remove_bond_add_ports
def test_remove_bond_add_ports(self, hydrogen):
h_clone = mb.clone(hydrogen)
h2 = mb.Compound(subcompounds=(hydrogen, h_clone))
mb.force_overlap(h_clone, h_clone['up'], hydrogen['up'])
h2.remove_bond((h2[0], h2[1]))
assert len(h2.all_ports()) == 2
assert len(hydrogen.all_ports()) == 1
assert len(h_clone.all_ports()) == 1
示例14: fill_box
def fill_box(compound, n_compounds, box, overlap=0.2, seed=12345):
"""Fill a box with a compound using packmol.
Parameters
----------
compound : mb.Compound or list of mb.Compound
n_compounds : int or list of int
box : mb.Box
overlap : float
Returns
-------
filled : mb.Compound
"""
if not PACKMOL:
msg = "Packmol not found."
if sys.platform.startswith("win"):
msg = (msg + " If packmol is already installed, make sure that the "
"packmol.exe is on the path.")
raise IOError(msg)
box = _validate_box(box)
if not isinstance(compound, (list, set)):
compound = [compound]
if not isinstance(n_compounds, (list, set)):
n_compounds = [n_compounds]
# In angstroms for packmol.
box_mins = box.mins * 10
box_maxs = box.maxs * 10
overlap *= 10
# Build the input file for each compound and call packmol.
filled_pdb = tempfile.mkstemp(suffix='.pdb')[1]
input_text = PACKMOL_HEADER.format(overlap, filled_pdb, seed)
for comp, m_compounds in zip(compound, n_compounds):
m_compounds = int(m_compounds)
compound_pdb = tempfile.mkstemp(suffix='.pdb')[1]
comp.save(compound_pdb, overwrite=True)
input_text += PACKMOL_BOX.format(compound_pdb, m_compounds,
box_mins[0], box_mins[1], box_mins[2],
box_maxs[0], box_maxs[1], box_maxs[2])
proc = Popen(PACKMOL, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
out, err = proc.communicate(input=input_text)
if err:
_packmol_error(out, err)
# Create the topology and update the coordinates.
filled = Compound()
for comp, m_compounds in zip(compound, n_compounds):
for _ in range(m_compounds):
filled.add(clone(comp))
filled.update_coordinates(filled_pdb)
return filled
示例15: __init__
def __init__(self):
super(Hexane, self).__init__()
self.add(propyl, 'propyl1')
self.add(mb.clone(propyl), 'propyl2')
mb.force_overlap(self['propyl1'],
self['propyl1']['down'],
self['propyl2']['down'])