def initialize(job): water = create_spce_water() water.name = 'SOL' pore = mb.recipes.GraphenePoreSolvent( pore_width=1.0, pore_length=1.0, pore_depth=1.1, n_sheets=1, slit_pore_dim=2, solvent=water, n_solvent=24, x_bulk=0, ) ff = foyer.Forcefield(get_ff("pore-spce.xml")) water = mb.Compound() gph = mb.Compound() for child in pore.children: if child.name == 'SOL': water.add(mb.clone(child)) else: gph.add(mb.clone(child)) typed_water = ff.apply(water, residues='SOL', combining_rule='lorentz') typed_gph = ff.apply(gph, combining_rule='lorentz') typed_pore = typed_gph + typed_water typed_pore.box[1] = 20 with job: write_lammpsdata(typed_pore, 'data.spce') typed_pore.save('init.mol2', overwrite=True) typed_pore.save('init.gro', combine='all', overwrite=True)
def initialize(job): water = create_spce_water() water.name = 'SOL' pore = mb.recipes.GraphenePoreSolvent( pore_width=2.0, pore_length=3.0, pore_depth=3.0, n_sheets=3, slit_pore_dim=2, solvent=water, n_solvent=job.sp.nwater, x_bulk=0, ) pore.periodicity[1] = 6.0 ff = foyer.Forcefield(get_ff("pore-spce.xml")) water = mb.Compound() gph = mb.Compound() for child in pore.children: if child.name == 'SOL': water.add(mb.clone(child)) else: gph.add(mb.clone(child)) typed_water = ff.apply(water, residues='SOL', combining_rule='lorentz') typed_gph = ff.apply(gph, combining_rule='lorentz') typed_pore = typed_gph + typed_water typed_pore.box[1] = 60 with job: typed_pore.save('init.gro', combine='all', overwrite=True) typed_pore.save('init.top', combine='all', overwrite=True) typed_pore.save('init.mol2', overwrite=True) #add_settles('init.top') write_ndx(path='.')
surface = graphene_surface() x_length = np.max(surface.xyz[:, 0]) y_length = np.max(surface.xyz[:, 1]) z_length = np.max(surface.xyz[:, 2]) water = spce_water() water.name = 'SOL' water_region = mb.Box( mins=[0, 0, z_length+0.2], maxs=[x_length, y_length, z_length+2] ) water_box = mb.fill_box(water, box=water_region, density=1000) ff = Forcefield(get_ff('pore-spce.xml')) graphenePM = ff.apply(surface, combining_rule='lorentz', residues='RES') waterPM = ff.apply(water_box, combining_rule='lorentz', residues='SOL') system = graphenePM + waterPM system.save('init.gro', combine='all', overwrite=True) system.save('init.top', combine='all', overwrite=True) system.save('init.mol2', overwrite=True) add_settles('init.top') write_ndx()
def md_files(job): import mbuild as mb import foyer water = create_spce_water() water.name = "SOL" pore = mb.recipes.GraphenePoreSolvent( pore_width=1.0, pore_length=1.0, pore_depth=1.1, n_sheets=1, slit_pore_dim=2, solvent=water, n_solvent=job.sp.nwater, x_bulk=0, ) ff = foyer.Forcefield(get_ff("pore-spce.xml")) pore.translate([0, 0.3325, 0]) water = mb.Compound() gph = mb.Compound() for child in pore.children: if child.name == "SOL": water.add(mb.clone(child)) else: gph.add(mb.clone(child)) typed_water = ff.apply(water, residues="SOL", combining_rule="lorentz") typed_gph = ff.apply(gph, combining_rule="lorentz") typed_pore = typed_gph + typed_water typed_pore.box[1] = 20 with job: import os import glob import numpy as np import unyt as u import mbuild as mb from cp2kmdpy.molecule_optimization import ( Molecule_optimization, ) # for single molecule optimization from cp2kmdpy.md import MD # for running MD from cp2kmdpy import runners import setter typed_pore.save("init.mol2", overwrite=True) temperature = job.sp.T * u.K # Defining the molecule we want to simulate graphene_water = mb.load("init.mol2") molecule = graphene_water box = mb.box.Box(lengths=[0.9824, 2, 1.0635]) q = MD( molecules=[molecule], box=box, cutoff=650, functional="BLYP", basis_set={ "C": "DZVP-MOLOPT-SR-GTH", "H": "DZVP-MOLOPT-SR-GTH", "O": "DZVP-MOLOPT-SR-GTH", }, periodicity="XYZ", n_molecules=[1], traj_type="PDB", seed=1, project_name="carbon_water", initial_coordinate_filename="init.mol2", fixed_list="1..80", ) q.temperature = temperature q.ensemble = "NVT" q.simulation_time = 1000 * u.ps # Initializing q q.md_initialization() # generating input files setter.md_files(q) job.doc.input_filename = q.input_filename job.doc.output_filename = q.output_filename job.doc.restart_filename = q.project_name + "-1.restart"
def run_simulation(job): """Run GCMC simulations for the given statepoint""" import mbuild import foyer import unyt as u import numpy as np import mosdef_cassandra as mc from mosdef_slitpore.utils.cassandra_helpers import spce_water from mosdef_slitpore.utils.utils import get_ff temperature = job.sp.T * u.K mu = job.sp.mu * u.kJ / u.mol nsteps_eq = job.sp.nsteps.equil nsteps_prod = job.sp.nsteps.prod seed1 = job.sp.seed1 seed2 = job.sp.seed2 # Want box size to depend on chemical potential # Prelim simulation shows mu' = -48 kJ/mol; p ~ 0.01 bar # Employ IG law to estimate remaining box sizes; target 40 waters mu_0 = -48 * u.kJ / u.mol p_0 = 0.01 * u.bar n_water_target = 40 p_ig = p_0 * np.exp((mu - mu_0) / (u.kb * temperature)) vol = n_water_target * u.kb * temperature / p_ig boxl = (vol**(1. / 3.)).to_value("nm") # Define custom_args that are the same # for all pure phase simulations custom_args = { "cutoff_style": "cut", "charge_style": "ewald", "rcut_min": 0.5 * u.angstrom, "vdw_cutoff": 9.0 * u.angstrom, "charge_cutoff": 0.25 * boxl * u.nm, "prop_freq": 1000, "angle_style": ["fixed"], "seeds": [seed1, seed2], } # Create a water molecule with the spce geometry ff = foyer.Forcefield(get_ff("pore-spce.xml")) water_typed = ff.apply(spce_water) species_list = [water_typed] box_list = [mbuild.Box([boxl, boxl, boxl])] system = mc.System( box_list, species_list, ) moveset = mc.MoveSet("gcmc", species_list) moveset.prob_regrow = 0.0 moveset.prob_translate = 0.3 moveset.prob_rotate = 0.3 moveset.prob_insert = 0.2 with job: mc.run( system=system, moveset=moveset, run_type="equil", run_length=nsteps_eq, temperature=temperature, run_name="equil", chemical_potentials=[mu], **custom_args, ) mc.restart( system=system, moveset=moveset, run_type="prod", run_length=nsteps_prod, temperature=temperature, run_name="prod", restart_name="equil", chemical_potentials=[mu], **custom_args, )
def run_nvt(filled_pore, temperature, nsteps_eq, nsteps_prod, **custom_args): """Run an NVT MC simulation at the specified temperature Parameters ---------- filled_pore : porebuilder.GraphenePoreSolvent pore filled with water temperature: u.unyt_quantity (temperature) desired temperature nsteps_eq : int number of MC steps for NVT equilibration nsteps_prod : int number of MC steps for GCMC simulation custom_args : opt, additional keyword arguments provide additional custom keyword arguments to MoSDeF Cassandra and override the default values Returns ------- None: runs simulation """ # Load foyer ff ff = foyer.Forcefield(get_ff("pore-spce.xml")) # Extract just the pore and apply ff empty_pore = filled_pore.children[0] typed_pore = ff.apply(empty_pore) # Create a water molecule with the spce geometry and apply ff typed_water = ff.apply(spce_water) # Determine the number of waters in the pore nwater = len([child for child in filled_pore.children]) - 1 # Create box and species list box_list = [filled_pore] species_list = [typed_pore, typed_water] # Specify mols at start of the simulation mols_in_boxes = [[1, nwater]] # Create MC system system = mc.System(box_list, species_list, mols_in_boxes=mols_in_boxes) moves = mc.MoveSet("nvt", species_list) # Set move probabilities moves.prob_translate = 0.5 moves.prob_rotate = 0.5 moves.prob_regrow = 0.0 # Set thermodynamic properties thermo_props = [ "energy_total", "energy_intervdw", "energy_interq", ] default_args = { "run_name": "equil.nvt", "cutoff_style": "cut", "charge_style": "ewald", "rcut_min": 0.5 * u.angstrom, "vdw_cutoff": 9.0 * u.angstrom, "charge_cutoff": 9.0 * u.angstrom, "properties": thermo_props, "angle_style": ["harmonic", "fixed"], "coord_freq": 10000, "prop_freq": 1000, } custom_args = {**default_args, **custom_args} # Run NVT equilibration mc.run( system=system, moveset=moves, run_type="equilibration", run_length=nsteps_eq, temperature=temperature, **custom_args, ) # Run production custom_args["run_name"] = "prod.nvt" custom_args["restart_name"] = "equil.nvt" mc.restart( system=system, moveset=moves, run_type="production", run_length=nsteps_prod, temperature=temperature, **custom_args, )
def run_adsorption( empty_pore, pore_width, temperature, mu, nsteps, **custom_args, ): """Run adsorption simulation at the specified temperature and chemical potential Parameters ---------- empty_pore : porebuilder.GraphenePore empty pore system to simulate pore_width : u.unyt_quantity (length) width of pore for restricted insertions temperature: u.unyt_quantity (temperature) desired temperature mu : u.unyt_quantity (energy) desired chemical potential nsteps : int number of MC steps in simulation custom_args : opt, additional keyword arguments provide additional custom keyword arguments to MoSDeF Cassandra and override the default values Returns ------- None: runs simulation """ # Load foyer ff ff = foyer.Forcefield(get_ff("pore-spce.xml")) # Apply ff typed_pore = ff.apply(empty_pore) # Create a water molecule with the spce geometry typed_water = ff.apply(spce_water) # Create box and species list box_list = [empty_pore] species_list = [typed_pore, typed_water] # Specify mols at start of the simulation mols_in_boxes = [[1, 0]] # Create MC system system = mc.System(box_list, species_list, mols_in_boxes=mols_in_boxes) moves = mc.MoveSet("gcmc", species_list) # Set move probabilities moves.prob_translate = 0.25 moves.prob_rotate = 0.25 moves.prob_insert = 0.25 moves.prob_regrow = 0.0 # Specify the restricted insertion restricted_type = [[None, "slitpore"]] restricted_value = [[None, 0.5 * pore_width]] moves.add_restricted_insertions(species_list, restricted_type, restricted_value) # Set thermodynamic properties thermo_props = [ "energy_total", "energy_intervdw", "energy_interq", "nmols", ] default_args = { "run_name": "gcmc", "cutoff_style": "cut", "charge_style": "ewald", "rcut_min": 0.5 * u.angstrom, "vdw_cutoff": 9.0 * u.angstrom, "charge_cutoff": 9.0 * u.angstrom, "properties": thermo_props, "angle_style": ["harmonic", "fixed"], "coord_freq": 100000, "prop_freq": 1000, } custom_args = {**default_args, **custom_args} mc.run( system=system, moveset=moves, run_type="equilibration", run_length=nsteps, temperature=temperature, chemical_potentials=["none", mu], **custom_args, )