def monomer(): try: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'disGde.mol')) # s = system.read_pubchem_smiles('O=C(OCCSSCCC(O)=O)CC') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CC(C)C(=O)OC.mol')) f = forcefield.Gaff() s.apply_forcefield(f) c3 = s.particles[1] c4 = s.particles[2] for b in c3.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c3 else b.b s.particles.remove(pb.tag, update=False) break for b in c4.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c4 else b.b s.particles.remove(pb.tag, update=False) break s.remove_spare_bonding() c3.linker = 'head' c4.linker = 'tail' lmps.quick_min(s, min_style='cg') s.add_particle_bonding() s.apply_charges(f, charges='gasteiger') signal = 0 for pb in s.particles: if pb.elem == 'O' and 1 in pb.bond_orders and len(set( pb.bond_orders)) == 1: signal += 1 if signal == 2 and pb.elem == 'O' and 1 in pb.bond_orders and len( set(pb.bond_orders)) == 1: pb.charge = pb.charge - 1 return s
def run(test=False): # use a smiles string to query the pubchem search database and read the mol file returned from the http request # if cannot get to internet, read local cached response from pubchem try: s = system.read_pubchem_smiles('c1=cc=cc=c1') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'c1=cc=cc=c1.mol')) # the resulting system (benzene) has alternating double bonds # we want pysimm to recognize the ring as aromatic, so we define each bond in the ring to be bond order 'A' for b in s.bonds: if b.a.elem == 'C' and b.b.elem == 'C': b.order = 'A' # the resulting system has sufficient information to type with a forcefield, here we will use the Dreiding force field # we will also determine partial charges using the gasteiger algorithm s.apply_forcefield(forcefield.Dreiding(), charges='gasteiger') # we'll perform a 2 step energy minimization using the steepest decent and conjugate gradient algorithms in LAMMPS lmps.quick_min(s, min_style='sd', name='min_sd') lmps.quick_min(s, min_style='cg', name='min_cg') # write a few different file formats s.write_xyz('benzene.xyz') s.write_yaml('benzene.yaml') s.write_lammps('benzene.lmps') s.write_chemdoodle_json('benzene.json')
def monomer(): try: s = system.read_pubchem_smiles('CC(C)C(=O)OC') except: import os s = system.read_mol(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CC(C)C(=O)OC.mol')) f = forcefield.Dreiding() s.apply_forcefield(f) c3 = s.particles[3] c4 = s.particles[4] for b in c3.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c3 else b.b s.particles.remove(pb.tag, update=False) break for b in c4.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c4 else b.b s.particles.remove(pb.tag, update=False) break s.remove_spare_bonding() c3.linker = 'head' c4.linker = 'tail' lmps.quick_min(s, min_style='fire') s.add_particle_bonding() return s
def monomer(): try: s = system.read_pubchem_smiles('CC') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CC.mol')) f = forcefield.Gaff() s.apply_forcefield(f) c1 = s.particles[1] c2 = s.particles[2] c1.linker = 'head' c2.linker = 'tail' for b in c1.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c1 else b.b s.particles.remove(pb.tag, update=False) break for b in c2.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c2 else b.b s.particles.remove(pb.tag, update=False) break s.remove_spare_bonding() lmps.quick_min(s, min_style='fire') s.add_particle_bonding() return s
def test_read_v3000mol(self): # check the v2000 format mol file file_path = os.path.join(self.TEST_DATA_PATH, 'testfile.molv3000_input.mol') test_sst = system.read_mol(file_path, version='V3000') self.assertGreater(len(test_sst.particles), 0) self.assertGreater(len(test_sst.bonds), 0)
def monomer(): try: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'disIpro.mol')) # s = system.read_pubchem_smiles('CCC(OCCSSCCN)=O') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CC(C)C(=O)OC.mol')) f = forcefield.Dreiding() s.apply_forcefield(f) c3 = s.particles[1] c4 = s.particles[2] for b in c3.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c3 else b.b s.particles.remove(pb.tag, update=False) break for b in c4.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c4 else b.b s.particles.remove(pb.tag, update=False) break s.remove_spare_bonding() c3.linker = 'head' c4.linker = 'tail' lmps.quick_min(s, min_style='cg') s.add_particle_bonding() s.apply_charges(f, charges='gasteiger') for pb in s.particles: if pb.elem == 'N': pb.charge = pb.charge + 1.0 return s
def monomer(**kwargs): isomer = kwargs.get('isomer', {}) try: import os if isomer == 'endo': s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'NbTMS_H2_endo.mol')) elif isomer == 'exo_endo': s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'NbTMS_H2_exo_endo.mol')) else: s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'NbTMS_H2_exo_exo.mol')) except: print("!!!could not read mol!!!") raise f = forcefield.Dreiding() for b in s.bonds: if b.a.bonds.count == 3 and b.b.bonds.count == 3: b.order = 4 s.apply_forcefield(f) h = s.particles[7] t = s.particles[8] m = s.particles[32] s.remove_spare_bonding() s.set_box(padding=10) h.linker = 'head' t.linker = 'tail' m.linker = 'mirror' # lmps.quick_min(s, min_style='fire') s.add_particle_bonding() return s
def monomer(): try: s = system.read_pubchem_smiles('CCc1=cc=cc=c1') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CCc1=cc=cc=c1.mol')) m = s.molecules[1] f = forcefield.Gaff() for b in s.bonds: if b.a.bonds.count == 3 and b.b.bonds.count == 3: b.order = 4 s.apply_forcefield(f) c1 = s.particles[1] c5 = s.particles[5] for b in c1.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c1 else b.b s.particles.remove(pb.tag, update=False) break for b in c5.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c5 else b.b s.particles.remove(pb.tag, update=False) break s.remove_spare_bonding() s.set_box(padding=10) c1.linker = 'head' c5.linker = 'tail' lmps.quick_min(s, min_style='fire') s.add_particle_bonding() return s
def SPC(): try: s = system.read_pubchem_smiles('[H]O[H]') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CC.mol')) f = forcefield.Dreiding() s.apply_forcefield(f) for pb in s.particles: if pb.elem == 'H': pb.charge = 0.4238 elif pb.elem == 'O': pb.charge = -0.8476 lmps.quick_min(s, min_style='fire') return s
def run(test=False): # use a smiles string to query the pubchem search database and read the mol file returned from the http request try: s = system.read_pubchem_smiles('CO') except: import os s = system.read_mol(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'CO.mol')) # the resulting system has sufficient information to type with a forcefield, here we will use the GAFF2 force field s.apply_forcefield(forcefield.Gaff2()) # we'll perform energy minimization using the fire algorithm in LAMMPS lmps.quick_min(s, min_style='fire') # write a few different file formats s.write_xyz('methanol.xyz') s.write_yaml('methanol.yaml') s.write_lammps('methanol.lmps') s.write_chemdoodle_json('methanol.json')
def monomer(ff, is_capped=False): try: s = system.read_pubchem_smiles('CCc1=cc=cc=c1') except: import os s = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'topologies', 'CCc1=cc=cc=c1.mol')) for b in s.bonds: if b.a.bonds.count == 3 and b.b.bonds.count == 3: b.order = 4 c1 = s.particles[1] c5 = s.particles[5] c1.linker = 'head' c5.linker = 'tail' if not is_capped: for b in c1.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c1 else b.b s.particles.remove(pb.tag, update=False) break for b in c5.bonds: if b.a.elem == 'H' or b.b.elem == 'H': pb = b.a if b.b is c5 else b.b s.particles.remove(pb.tag, update=False) break s.remove_spare_bonding() s.apply_forcefield(ff, charges='gasteiger') s.set_box(padding=10) sim = lmps.Simulation(s, print_to_screen=False, log='ps_mon_relax.log') sim.add(lmps.Init()) sim.add_min(min_style='fire') sim.run() s.add_particle_bonding() return s
def get_types(): types = [] desc = [] molfile = request.form['mol'] ff = request.form['ff'] typer = request.form['typer'] s = system.read_mol(molfile) try: if ff == 'Dreiding': f = forcefield.Dreiding() s.apply_forcefield(f) elif ff == 'Polymer Consistent Force Field (PCFF)': f = forcefield.Pcff() s.apply_forcefield(f) elif ff == 'Generalized Amber Force Field (GAFF)': f = forcefield.Gaff2() if typer == 'pysimm': s.apply_forcefield(f) elif typer == 'antechamber': cwd = os.getcwd() tempdir = tempfile.mkdtemp() print(tempdir) os.chdir(tempdir) amber.get_forcefield_types(s, f=f) os.chdir(cwd) shutil.rmtree(tempdir) types = [p.type.name for p in s.particles] desc = [p.type.desc for p in s.particles] except: print('error typing occurred') p_elems = set(p.elem for p in s.particles) possible_types = {e: [] for e in p_elems} possible_types_desc = {e: [] for e in p_elems} for pt in f.particle_types: if pt.elem in p_elems: possible_types[pt.elem].append(pt.name) possible_types_desc[pt.elem].append(pt.desc) return jsonify(types=types, desc=desc, possible_types=possible_types, possible_types_desc=possible_types_desc)
def get_lmps(): molfile = request.form['mol'] type_names = map(lambda x: x.split()[-1], request.form.getlist('typeNames[]')) ff = request.form['ff'] if ff == 'Dreiding': f = forcefield.Dreiding() elif ff == 'Polymer Consistent Force Field (PCFF)': f = forcefield.Pcff() elif ff == 'Generalized Amber Force Field (GAFF)': f = forcefield.Gaff2() s = system.read_mol(molfile) types = { name: s.particle_types.add(f.particle_types.get(name)[0].copy()) for name in set(type_names) } for p, pname in zip(s.particles, type_names): p.type = types[pname] s.apply_forcefield(f, skip_ptypes=True) s.pair_style = f.pair_style return jsonify(lmpsData=s.write_lammps('string'))
def run(test=False): try: ethanol = system.read_pubchem_smiles('CCO') except: import os ethanol = system.read_mol(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'CCO.mol')) try: acetone = system.read_pubchem_smiles('CC(=O)C') except: import os acetone = system.read_mol(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'CC(=O)C.mol')) f = forcefield.Gaff2() ethanol.apply_forcefield(f, charges='gasteiger') acetone.apply_forcefield(f, charges='gasteiger') # amber.calc_charges(ethanol) # amber.calc_charges(acetone) lmps.quick_min(ethanol, min_style='fire') lmps.quick_min(acetone, min_style='fire') molecule_list = [ethanol, acetone] if test: n_molecules = [20, 20] else: n_molecules = [200, 200] s = system.replicate(molecule_list, n_molecules, density=0.3) min_settings = { 'name': 'cg_min', 'min_style': 'cg', 'maxiter': int(5e+5), 'maxeval': int(5e+6), } nvt_settings = { 'name': 'nvt_md', 'print_to_screen': True, 'ensemble': 'nvt', 'temperature': { 'start': 100, 'stop': 300 }, 'new_v': True, 'length': 2500 } npt_settings = { 'name': 'npt_md', 'print_to_screen': True, 'ensemble': 'npt', 'temperature': 300, 'new_v': True, 'pressure': { 'start': 1000, 'stop': 1 }, 'length': 5000, } npt_settings_add = { 'name': 'npt_md', 'print_to_screen': True, 'ensemble': 'npt', 'temperature': 300, 'new_v': True, 'pressure': { 'start': 1, 'stop': 1 }, 'length': 5000, } if test: nvt_settings['length'] = 2000 npt_settings['length'] = 2000 sim = lmps.Simulation(s) sim.add_min(**min_settings) sim.add(lmps.OutputSettings(thermo={'freq': 500, 'style': 'custom', 'args': ['step', 'temp', 'etotal', 'press', 'density']})) sim.add_md(**nvt_settings) sim.add_md(**npt_settings) sim.add_md(**npt_settings_add) sim.run() s.write_yaml('mixture.yaml') s.write_lammps('mixture.lmps')
import numpy from pysimm import lmps from pysimm import system from pysimm import forcefield sst = system.read_mol('ethylpropylether.mol') # decorate the system read from a simple .mol file and type it with CHARMM FF parameters and simple gasteiger charges for b in sst.bonds: b.order = 1 ff = forcefield.Charmm() sst.apply_forcefield(ff, charges='gasteiger') sst.set_charge() # also expand the system to a minimal size at which the periodic image convention is held bxSize = 25.0 sst.dim.dx = bxSize sst.dim.dy = bxSize sst.dim.dz = bxSize sst.center('box', [0.0, 0.0, 0.0], True) # read a water molecule from .lmps file that already contains all details solvnt = system.read_lammps('tipS3P.lmps', angle_style='charmm') # knowing volume of the box let's find out how many water molecules are needed to feet at each side of a cubic box: solvnt.set_mass() ngrid = numpy.floor(((bxSize ** 3) * 0.6022 / solvnt.mass) ** (1.0 / 3.0)) # put water molecules in the nodes of a regular grid rng = numpy.linspace(sst.dim.xlo, sst.dim.xhi, int(ngrid) + 1) count = 0
def run(test=False): try: ethanol = system.read_pubchem_smiles('CCO') except: import os ethanol = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'CCO.mol')) try: acetone = system.read_pubchem_smiles('CC(=O)C') except: import os acetone = system.read_mol( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'CC(=O)C.mol')) f = forcefield.Gaff2() ethanol.apply_forcefield(f, charges='gasteiger') acetone.apply_forcefield(f, charges='gasteiger') # amber.calc_charges(ethanol) # amber.calc_charges(acetone) lmps.quick_min(ethanol, min_style='fire') lmps.quick_min(acetone, min_style='fire') molecule_list = [ethanol, acetone] if test: n_molecules = [30, 20] else: n_molecules = [300, 200] s = system.replicate(molecule_list, n_molecules, density=0.3) min_settings = { 'name': 'fire_min', 'min_style': 'fire', 'print_to_screen': True } nvt_settings = { 'name': 'nvt_md', 'print_to_screen': True, 'ensemble': 'nvt', 'temperature': { 'start': 100, 'stop': 300 }, 'new_v': True, 'length': 10000 } npt_settings = { 'name': 'npt_md', 'print_to_screen': True, 'ensemble': 'npt', 'temperature': 300, 'new_v': True, 'pressure': { 'start': 1000, 'stop': 1 }, 'length': 100000, 'thermo_style': 'custom step temp press density' } if test: nvt_settings['length'] = 2000 npt_settings['length'] = 2000 lmps.quick_min(s, **min_settings) lmps.quick_md(s, **nvt_settings) lmps.quick_md(s, **npt_settings) s.write_xyz('mixture.xyz') s.write_yaml('mixture.yaml') s.write_lammps('mixture.lmps') s.write_chemdoodle_json('mixture.json')
'PySIMM:', *a) if pysimm.verbose else lambda *a, **k: None pysimm.debug_print = lambda *a, **k: print( '(debug) PySIMM:', *a) if pysimm.debug else lambda *a, **k: None print('\nWelcome to the pySIMM command line interface\n') print( 'This is no more than a python2.7 interactive shell with certain pySIMM modules imported for your convenience' ) print('Importing modules now...') from pysimm import system, amber, lmps, forcefield if args.lammps_data: s = system.read_lammps(args.lammps_data) elif args.molfile: s = system.read_mol(args.molfile) if args.forcefield and args.forcefield in supported_forcefields: if args.forcefield.lower() == 'dreiding': print('typing with %s' % args.forcefield) s.apply_forcefield(forcefield.Dreiding()) elif args.forcefield.lower() == 'pcff': s.apply_forcefield(forcefield.Pcff()) elif args.forcefield: print('forcefield %s is not supported in ' 'command line interface at this time') elif args.cml_file: s = system.read_cml(args.cml_file) elif args.yaml_file: s = system.read_yaml(args.yaml_file) elif args.lmps2xyz: s = system.read_lammps(args.lmps2xyz[0])