def test_lateral_dims_near_x_y_spec(self): from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) x = 4 y = 4 droplet = GrapheneDroplet(radius=1, angle=90.0, fluid=water, density=997, x=x, y=y) assert (abs(droplet.boundingbox.lengths[0] - x) < 0.5 and abs(droplet.boundingbox.lengths[1] - y) < 0.5)
def test_save(self, GrapheneDroplet): GrapheneDroplet.save('droplet.gro', overwrite=True, combine='all')
def test_init_with_too_large_y(self): from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) with pytest.raises(ValueError, match="y .* 100"): GrapheneDroplet(radius=1, angle=90.0, fluid=water, density=997, x=4, y=101)
def test_init_with_too_small_x(self): from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) with pytest.raises(ValueError, match="x .* at least"): GrapheneDroplet(radius=1, angle=90.0, fluid=water, density=997, x=1, y=4)
def test_init_with_lattice_without_lattice_compound(self, GoldLattice): from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) with pytest.raises(ValueError, match="Lattice compounds"): GrapheneDroplet(radius=1, angle=90.0, fluid=water, density=997, x=4, y=4, lattice=GoldLattice)
def test_init_without_lattice_with_lattice_compound(self): lattice_compound = mbuild.Compound(name='Au') from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) with pytest.raises(ValueError, match="do not specify lattice_compound"): GrapheneDroplet(radius=1, angle=90.0, fluid=water, density=997, x=4, y=4, lattice_compound=lattice_compound)
def test_init_with_missing_density(self): from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) with pytest.raises(ValueError, match="Fluid density"): GrapheneDroplet(radius=1, angle=90.0, fluid=water)
def test_init_with_missing_fluid(self): from dropletbuilder.dropletbuilder import GrapheneDroplet with pytest.raises(ValueError, match="Fluid droplet compounds"): GrapheneDroplet(radius=1, angle=90.0, density=997)
def GrapheneDropletWithDims(self): from dropletbuilder.dropletbuilder import GrapheneDroplet water = mbuild.load(get_fn('tip3p.mol2')) return GrapheneDroplet(radius=1, angle=90.0, fluid=water, density=997, x=4, y=4)
lattice_spacing = [0.40788, 0.40788, 0.40788] lattice_vector = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] gold_locations = [[0., 0., 0.], [.5, .5, 0.], [.5, 0., .5], [0, .5, .5]] basis = {lattice_compound.name: gold_locations} gold_lattice = mbuild.Lattice(lattice_spacing=lattice_spacing, lattice_vectors=lattice_vector, lattice_points=basis) # hexane compound hexane = Alkane(n=6) hexane.name = 'HEX' # build the system system = GrapheneDroplet(radius=3, angle=90, fluid=hexane, density=655, lattice=gold_lattice, lattice_compound=lattice_compound) # get and apply forcefields AU = Forcefield(get_fn('heinz2008.xml')) OPLSAA = Forcefield(name='oplsaa') for child in system.children: if child.name == 'LAT': lattice_pmd = AU.apply(child.to_parmed(residues='HEX')) elif child.name == 'FLD': hex_pmd = OPLSAA.apply(child.to_parmed(residues='Au')) else: continue
from dropletbuilder.dropletbuilder import GrapheneDroplet import mbuild from dropletbuilder.utils.io_tools import get_fn from foyer import Forcefield # water compound water = mbuild.load(get_fn('tip3p.mol2')) # build the system system = GrapheneDroplet(radius=2, angle=110.0, fluid=water, density=997) # get and apply forcefields GPH = Forcefield(get_fn('graphene.xml')) TIP3P = Forcefield(get_fn('tip3p.xml')) for child in system.children: if child.name == 'LAT': lattice_pmd = GPH.apply(child.to_parmed(residues='LAT')) elif child.name == 'FLD': water_pmd = TIP3P.apply(child.to_parmed(residues='FLD')) else: continue periodicity = system.periodicity system = lattice_pmd + water_pmd system.box[2] = periodicity[2] * 100 system.save('water_graphene_drop.gro', overwrite=True, combine='all') system.save('water_graphene_drop.top', overwrite=True, combine='all')