Beispiel #1
0
def equil(s, **kwargs):
    """pysimm.apps.equilibrate.equil

    Runs a 21-step compression/decompression equilibration algorithm

    Args:
        s: :class:`~pysimm.system.System` object
        tmax: maximum temperature during equilibration
        pmax: maximum pressure during equilibration
        tfinal: desired final temperature of final system
        pfinal: desired final pressure of final system
        np: number of processors to use during equilibration simulations
        p_steps: list of pressures to use during equilibration (must match length of length_list)
        length_list: list of simulation durations to use during equilibration (must match length of p_steps)

    Returns:
        None
    """
    tmax = kwargs.get('tmax', 1000)
    pmax = kwargs.get('pmax', 50000)
    tfinal = kwargs.get('tfinal', 300)
    pfinal = kwargs.get('pfinal', 1)
    
    init = kwargs.get('init')
    output_settings = kwargs.get('output_settings')

    np = kwargs.get('np')

    p_list = kwargs.get('p_steps', [0.02*pmax, 0.6*pmax, pmax, 0.5*pmax, 0.1*pmax, 0.01*pmax, pfinal])

    length_list = kwargs.get('length_list', [100000, 100000, 100000, 100000, 100000, 100000, 100000])

    sim = lmps.Simulation(s, name='equil', **kwargs)
    
    if init:
        sim.add(init)
    if output_settings:
        sim.add(output_settings)
        
    sim.add(lmps.Velocity(temperature=tfinal))

    step = 0
    for p, l in izip(p_list, length_list):
        step += 1
        if l:
            sim.add_md(length=l/2, ensemble='nvt', temperature=tmax, **kwargs)
            sim.add_md(length=l, ensemble='nvt', temperature=tfinal, **kwargs)
            sim.add_md(length=l/2, ensemble='npt', temperature=tfinal, pressure=p, **kwargs)

    sim.run(np=np)

    s.write_lammps('equil.lmps')
    s.write_xyz('equil.xyz')
Beispiel #2
0
 def stepwise_cooling(self):
     sim = lmps.Simulation(self.polymer, name='cool', log='log.cool')
     if self.calc_voronoi:
         sim.add('compute voronoi all voronoi/atom')
     sim.add(self.cool_output)
     for temp in self.cool_temp_range:
         velocity = lmps.Velocity(style='scale', temperature=temp)
         md = lmps.MolecularDynamics(ensemble='npt',
                                     temperature=temp,
                                     pressure=1.,
                                     run=self.cool_step_time,
                                     timestep=1)
         sim.add(velocity)
         sim.add(md)
     sim.run(np=self.nproc)
Beispiel #3
0
def lmps_cycle_npt_md(s, bonds, settings):
    """pysimm.apps.polymatic.lmps_cycle_npt_md

    Runs LAMMPS npt cycle md for the Polymatic algorithm.

    Args:
        s: :class:`~pysimm.system.System` to minimize
        bonds: number of bond to be made
        settings: object containing Polymatic settings

    Returns:
        result from lmps.md
    """
    if settings.polym.cycle_npt.cluster:
        nanohub = {'cores': int(settings.polym.cycle_npt.nanohub_cores),
                   'walltime': int(settings.polym.cycle_npt.nanohub_walltime)}
        log_name = 'cycle_npt_%03d' % bonds
    else:
        nanohub = {}
        log_name = 'logs/cycle_npt_%03d' % bonds

    if settings.polym.cycle_npt.user_input:
        sim = lmps.Simulation(s, name='bond %d cycle npt' % bonds,
                 print_to_screen=False, nanohub=nanohub, custom=True)
        sim.add(settings.polym.cycle_npt.step_in)
        sim.run(np=settings.np, nanohub=nanohub)
    else:
        sim = lmps.Simulation(s, name='bond %d cycle npt' % bonds,
            print_to_screen=False, nanohub=nanohub,
            log=log_name
        )
        sim.add(lmps.Init(cutoff=settings.polym.cycle_npt.nb_cutoff, forcefield=settings.forcefield))
        sim.add(lmps.Velocity(temperature=settings.polym.cycle_npt.temp))
        sim.add_md(
            ensemble='npt', temperature=settings.polym.cycle_npt.nb_cutoff,
            run=settings.polym.cycle_npt.length,
            pressure=settings.polym.cycle_npt.pressure,
        )
        sim.run(np=settings.np, nanohub=nanohub)

    if settings.polym.cycle_npt.cluster:
        shutil.move(log_name, 'logs')

    return True
Beispiel #4
0
def lmps_step_md(s, bonds, attempt, settings):
    """pysimm.apps.polymatic.lmps_step_md

    Runs LAMMPS step md for the Polymatic algorithm.

    Args:
        s: :class:`~pysimm.system.System` to minimize
        bonds: number of bond to be made
        attempt: number of bonding attempt
        settings: object containing Polymatic settings

    Returns:
        result from :func:`~pysimm.lmps.md`
    """
    if settings.polym.step.cluster:
        nanohub = {'cores': int(settings.polym.step.nanohub_cores),
                   'walltime': int(settings.polym.step.nanohub_walltime)}
        log_name = 'step_%03d_%03d' % (bonds, attempt)
    else:
        nanohub = {}
        log_name = 'logs/step_%03d_%03d' % (bonds, attempt)

    if settings.polym.step.user_input:
        sim = lmps.Simulation(s, name='bond %s attempt #%d' % (bonds + 1, attempt),
                 print_to_screen=False, nanohub=nanohub, custom=True)
        sim.add(settings.polym.step.step_in)
        sim.run(np=settings.np, nanohub=nanohub)
    else:
        sim = lmps.Simulation(s, name='bond %s: attempt #%d' % (bonds + 1, attempt),
            print_to_screen=False, nanohub=nanohub,
            log=log_name
        )
        sim.add(lmps.Init(cutoff=settings.polym.step.nb_cutoff, forcefield=settings.forcefield))
        sim.add(lmps.Velocity(temperature=settings.polym.step.temp))
        sim.add_md(
            ensemble='nvt', temperature=settings.polym.step.temp,
            run=settings.polym.step.length,
        )
        sim.run(np=settings.np, nanohub=nanohub)

    if settings.polym.step.cluster:
        shutil.move(log_name, 'logs')

    return True
Beispiel #5
0
def mc_md(gas_sst,
          fixed_sst=None,
          mcmd_niter=None,
          sim_folder=None,
          mc_props=None,
          md_props=None,
          **kwargs):
    """pysimm.apps.mc_md

    Performs the iterative hybrid Monte-Carlo/Molecular Dynamics (MC/MD) simulations using :class:`~pysimm.lmps` for
    MD and :class:`~pysimm.cassandra` for MC

    Args:
        gas_sst (list of :class:`~pysimm.system.System`) : list items describe a different molecule to be
            inserted by MC
        fixed_sst (:class:`~pysimm.system.System`) : fixed during th MC steps group of atoms (default: None)


    Keyword Args:
        mcmd_niter (int) : number of MC-MD iterations (default: 10)
        sim_folder (str): relative path to the folder with all simulation files (default: 'results')
        mc_props (dictionary) : description of  all MC properties needed for simulations (see
            :class:`~pysimm.cassandra.GCMC` and :class:`~pysimm.cassandra.GCMC.props` for details)
        md_props (dictionary):  description of all Molecular Dynamics settings needed for simulations (see
            :class:`~pysimm.lmps.Simulation` and :class:`~pysimm.lmps.MolecularDynamics` for details)

    Returns:
        :class:`~pysimm.system.System`:
            Final state of the simulated system
    """

    nonrig_group_name = 'nonrigid_b'
    rig_group_name = 'rigid_b'
    n_iter = mcmd_niter or 10
    sim_folder = sim_folder or 'results'
    xyz_fname = os.path.join(sim_folder, 'MD{:}_out.xyz')
    l = 1

    # Creating fixed polymer system
    fs = None
    if fixed_sst:
        if isinstance(fixed_sst, system.System):
            fs = fixed_sst
            fs.wrap()
        else:
            print(
                'Cannot setup the fixed system for the simulations. Skipping this'
            )

    # Set the one-molecule gas systems
    gases = []
    if gas_sst:
        if isinstance(gas_sst, system.System):
            gases = [gas_sst]
        elif isinstance(gas_sst, types.ListType):
            for g in cassandra.make_iterable(gas_sst):
                if isinstance(g, system.System):
                    gases.append(g)

    if not gases:
        print(
            'There are no gas molecules were specified correctely\nThe gas molecules are needed to start the '
            'MC-MD simulations\nExiting...')
        exit(1)

    css = cassandra.Cassandra(fixed_sst)
    # Set the Monte-Carlo properties:
    mcp = mc_props
    if mcp:
        CHEM_POT = cassandra.make_iterable(mcp.get('Chemical_Potential_Info'))
        if not CHEM_POT:
            print('Missing chemical potential info\nExiting...')
            exit(1)
    else:
        print('Missing the MC Simulation settings\nExiting...')
        exit(1)
    mcp['Start_Type'] = OrderedDict([('species', [1] + [0] * len(CHEM_POT))])

    # Set the Molecular-Dynamics properties:
    sim = None
    mdp = md_props
    if not mdp:
        print('Missing the MD Simulation settings\nExiting...')
        exit(1)

    while l < n_iter + 1:
        mcp['Run_Name'] = str(l) + '.gcmc'

        css.add_gcmc(species=gases,
                     is_new=True,
                     chem_pot=CHEM_POT,
                     is_rigid=mcp.get('rigid_type') or [False] * len(gases),
                     out_folder=sim_folder,
                     props_file=str(l) + '.gcmc_props.inp',
                     **mcp)
        css.run()

        # >>> 2N: MD (LAMMPS) step:
        sim_sst = css.system
        sim_sst.write_lammps(
            os.path.join(sim_folder,
                         str(l) + '.before_md.lmps'))
        sim = lmps.Simulation(sim_sst,
                              debug=True,
                              log=os.path.join(sim_folder,
                                               str(l) + '.md.log'))

        sim.add(lmps.Init(cutoff=mdp.get('cutoff')))

        # custom definitions for the neighbour list updates
        sim.add_custom(
            'neighbor 1.0 nsq \nneigh_modify once no every 1 delay 0 check yes'
        )

        # adding group definitions to separate rigid and non-rigid bodies
        sim.add(
            lmps.Group('matrix', 'id',
                       css.run_queue[0].group_by_id('matrix')[0]))
        sim.add(
            lmps.Group(nonrig_group_name, 'id',
                       css.run_queue[0].group_by_id('nonrigid')[0]))
        rigid_mols = css.run_queue[0].group_by_id('rigid')[0]
        if rigid_mols:
            sim.add(lmps.Group(rig_group_name, 'id', rigid_mols))

        # adding "run 0" line before velocities rescale for correct temperature init of the system with rigid molecules
        sim.add(lmps.Velocity(style='create'))
        if rigid_mols:
            sim.add_custom('run 0')
            sim.add(lmps.Velocity(style='scale'))

        # create the description of the molecular dynamics simulation
        sim.add_md(
            lmps.MolecularDynamics(
                name='main_fix',
                group=nonrig_group_name if rigid_mols else 'all',
                ensemble='npt',
                timestep=mdp.get('timestep'),
                temperature=mdp.get('temp'),
                pressure=mdp.get('pressure'),
                run=False,
                extra_keywords={'dilate': 'all'} if rigid_mols else {}))

        # create the second NVT fix for rigid molecules that cannot be put in NPT fix
        if rigid_mols:
            sim.add(
                lmps.MolecularDynamics(name='rig_fix',
                                       ensemble='rigid/nvt/small molecule',
                                       timestep=mdp.get('timestep'),
                                       length=mdp.get('length'),
                                       group=rig_group_name,
                                       temperature=mdp.get('temp'),
                                       pressure=mdp.get('pressure'),
                                       run=False))

        # add the "spring tether" fix to the geometrical center of the system to avoid system creep
        sim.add_custom(
            'fix tether_fix matrix spring tether 30.0 0.0 0.0 0.0 0.0')
        sim.add(
            lmps.OutputSettings(thermo=mdp.get('thermo'),
                                dump={
                                    'filename':
                                    os.path.join(sim_folder,
                                                 str(l) + '.md.dump'),
                                    'freq':
                                    int(mdp.get('dump'))
                                }))
        sim.add_custom('run {:}\n'.format(mdp.get('length')))

        # The input for correct simulations is set, starting LAMMPS:
        sim.run(np=mdp.get('np', 1))

        # Updating the size of the fixed system from the MD simulations and saving the coordinates for the next MC
        css.system.dim = sim.system.dim
        sim.system.write_xyz(xyz_fname.format(l))
        mcp['Start_Type']['file_name'] = xyz_fname.format(l)
        mcp['Start_Type']['species'] = [1] + [0] * len(CHEM_POT)
        l += 1

    return sim.system if sim else None
Beispiel #6
0
                sst.add(tmp, change_dim=False, update_properties=False)

# because 2 systems have been combined let's reassign non-diagonal LJ interactions
ff.assign_extra_ljtypes(sst)

sst.write_lammps('to_sim.lmps')

# Create simulation and directly add all nondiagonal LJ parameters to the run file
# (that is how LAMMPS operates)
sim = lmps.Simulation(sst, log='simulation.log', cutoff={'inner_lj': 10.0, 'lj': 12.0})
if sst.nondiag_lj_types:
    for nd_lj in sst.nondiag_lj_types:
        sim.add_custom('pair_coeff {} {} {}'.format(' '.join(map(str, nd_lj.atm_types)), nd_lj.epsilon, nd_lj.sigma))

# define velocities and output settings
sim.add(lmps.Velocity(temperature=300.0, style='create'))
sim.add(lmps.OutputSettings(thermo={'args': ['step', 'time', 'temp', 'density', 'etotal', 'epair']}))

# setup shake for H-O bond and H-O-H angle for the whole simulation system
sim.add_custom('fix shck_fix all shake 0.001 40 0 b {:} a {:}\n'.format(sst.bond_types.get('H,O')[0].tag,
                                                                        sst.angle_types.get('H,O,H')[0].tag))
sim.add(lmps.MolecularDynamics(name='main',
                               pressure={'iso': 'iso', 'damp': 100},
                               ensemble='npt',
                               timestep=1,
                               temperature=300.0,
                               run=int(5e+4)))
sim.run()

sst.write_lammps('eth_propether.wtr_solution.lmps')
Beispiel #7
0
def pack_and_equil(A, n, x, f, prefix):
    # A: monomer
    # n: number of monomers
    # x: number of chains
    # f: forcefield
    # prefix: prefix for output files

    # run the polymer random walk tacticity method with n total repeat units
    polymer = random_walk_tacticity(A,
                                    n,
                                    forcefield=f,
                                    capped=True,
                                    tacticity='syndiotactic',
                                    rotation=180,
                                    error_check=False,
                                    sim=0)
    write_file_formats(polymer, prefix + "_1", unwrap=True)

    # quick opt of polymer
    lmps.quick_min(polymer, min_style='fire', etol=1.0e-4, maxiter=100000)

    # write a few different file formats
    polymer.unwrap()
    write_file_formats(polymer, prefix + "_1_fire")

    # pack x copies of polymer
    polymers = system.replicate(polymer, x, density=0.005)
    # polymers = polymer
    write_file_formats(polymers, prefix + "_" + str(x))
    lmps.quick_min(polymers, min_style='fire', etol=1.0e-4, maxiter=100000)
    write_file_formats(polymers, prefix + "_" + str(x) + "_fire")

    # quickmd
    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'
    }
    # npt calcs need "add neigh_modify" command to reneighbor more often during compression of npt step
    sim = lmps.Simulation(polymers, name='npt_reneighbor', debug=True)
    sim.add_custom('neigh_modify delay 0')
    sim.add(lmps.Velocity(temperature=1000))
    sim.add_md(length=10000, ensemble='npt', temperature=1000, pressure=5000)
    sim.run()
    write_file_formats(polymers, prefix + "_" + str(x) + "_npt")
    write_file_formats(polymers,
                       prefix + "_" + str(x) + "_npt_unwrapped",
                       unwrap=True)

    # 21-step equilibration
    equil(polymers, np=1, pmax=50000)
    write_file_formats(polymers, prefix + "_" + str(x) + "_equil")
    write_file_formats(polymers,
                       prefix + "_" + str(x) + "_equil_unwrapped",
                       unwrap=True)
Beispiel #8
0
def mc_md(gas_sst, fixed_sst=None, mc_props=None, md_props=None, **kwargs):
    """pysimm.apps.mc_md

    Performs the iterative hybrid Monte-Carlo/Molecular Dynamics (MC/MD) simulations using :class:`~pysimm.lmps` for
    MD and :class:`~pysimm.cassandra` for MC

    Args:
        gas_sst (list of :class:`~pysimm.system.System`) : list items describe a different molecule to be
            inserted by MC
        fixed_sst (:class:`~pysimm.system.System`) : fixed during th MC steps group of atoms (default: None)


    Keyword Args:
        mcmd_niter (int) : number of MC-MD iterations (default: 10)
        sim_folder (str): relative path to the folder with all simulation files (default: 'results')
        mc_props (dictionary) : description of  all MC properties needed for simulations (see
            :class:`~pysimm.cassandra.GCMC` and :class:`~pysimm.cassandra.GCMC.props` for details)
        md_props (dictionary):  description of all Molecular Dynamics settings needed for simulations (see
            :class:`~pysimm.lmps.Simulation` and :class:`~pysimm.lmps.MolecularDynamics` for details)

    Returns:
        :class:`~pysimm.system.System`:
            Final state of the simulated system
    """

    nonrig_group_name = 'nonrigid_b'
    rig_group_name = 'rigid_b'
    n_iter = kwargs.get('mcmd_niter', 10)
    sim_folder = kwargs.get('sim_folder', 'results')
    xyz_fname = os.path.join(sim_folder, '{:}.md_out.xyz')
    lmps_fname = os.path.join(sim_folder, '{:}.before_md.lmps')

    # Define whether the simulations should be continued or start from the scratch
    l = 1
    is_restart = kwargs.get('restart')
    if is_restart:
        for f in glob.glob(lmps_fname.format('*')):
            l = max(l, int(re.match('\A\d+', os.path.split(f)[1]).group()))

        to_purge = glob.glob(os.path.join(sim_folder, '{:}.*'.format(l + 1))) + \
                   glob.glob(os.path.join(sim_folder, '{:}.md*'.format(l)))
        for f in to_purge:
            os.remove(f)
    # Creating fixed polymer system
    fs = None
    if fixed_sst:
        if isinstance(fixed_sst, system.System):
            fs = fixed_sst
            fs.wrap()
        else:
            print('Cannot setup the fixed system for the simulations. Skipping this')

    # Set the one-molecule gas systems
    gases = []
    if gas_sst:
        if isinstance(gas_sst, system.System):
            gases = [gas_sst]
        elif isinstance(gas_sst, types.ListType):
            for g in cassandra.make_iterable(gas_sst):
                if isinstance(g, system.System):
                    gases.append(g)

    if not gases:
        print('There are no gas molecules were specified correctely\nThe gas molecules are needed to start the '
              'MC-MD simulations\nExiting...')
        exit(1)

    css = cassandra.Cassandra(fixed_sst)
    # Set the Monte-Carlo properties:
    mcp = mc_props
    if mcp:
        CHEM_POT = cassandra.make_iterable(mcp.get('Chemical_Potential_Info'))
        if not CHEM_POT:
            print('Missing chemical potential info\nExiting...')
            exit(1)
    else:
        print('Missing the MC Simulation settings\nExiting...')
        exit(1)
    mcp['Start_Type'] = OrderedDict([('species', [1] + [0] * len(CHEM_POT))])

    # Set the Molecular-Dynamics properties:
    sim = None
    mdp = md_props
    if not mdp:
        print('Missing the MD Simulation settings\nExiting...')
        exit(1)

    # De-synchronizing type names of the framework and the gases to avoid consolidation of types that PySIMM system does
    for gi, g in enumerate(gases):
        for pt in g.particle_types:
            pt.name += '_g' + str(gi + 1)

    while l < n_iter + 1:
        # >>> MC (CASSANDRA) step:
        mcp['Run_Name'] = str(l) + '.gcmc'

        css.add_gcmc(species=gases, is_new=True, chem_pot=CHEM_POT,
                     is_rigid=mcp.get('rigid_type') or [False] * len(gases),
                     out_folder=sim_folder, props_file=str(l) + '.gcmc_props.inp', **mcp)

        if is_restart:
            # Set gas particles positions from the .chk file, and update some properties
            css.run_queue[-1].upd_simulation()
            css.system = css.run_queue[-1].tot_sst.copy()
            # Set frame particles position and box size dimension from the .lmps file
            tmp_sst = system.read_lammps(lmps_fname.format(l))
            for p in css.system.particles:
                p.x = tmp_sst.particles[p.tag].x
                p.y = tmp_sst.particles[p.tag].y
                p.z = tmp_sst.particles[p.tag].z
            css.system.dim = tmp_sst.dim
            is_restart = False
        else:
            css.run()
            css.system.write_lammps(lmps_fname.format(l))

        nm_treads = '1'
        if 'OMP_NUM_THREADS' in os.environ.keys():
            nm_treads = os.environ['OMP_NUM_THREADS']
        os.environ['OMP_NUM_THREADS'] = '1'

        # >>> MD (LAMMPS) step:
        sim_sst = css.system.copy()
        sim_sst.write_lammps(os.path.join(sim_folder, str(l) + '.before_md.lmps'))
        sim = lmps.Simulation(sim_sst, print_to_screen=mdp.get('print_to_screen', False),
                              log=os.path.join(sim_folder, str(l) + '.md.log'))

        sim.add(lmps.Init(cutoff=mdp.get('cutoff'),
                          special_bonds=mdp.get('special_bonds'),
                          pair_modify=mdp.get('pair_modify')))

        # custom definitions for the neighbour list updates
        sim.add_custom('neighbor 1.0 nsq \nneigh_modify once no every 1 delay 0 check yes')

        # adding group definitions to separate rigid and non-rigid bodies
        sim.add(lmps.Group('matrix', 'id', css.run_queue[0].group_by_id('matrix')[0]))
        sim.add(lmps.Group(nonrig_group_name, 'id', css.run_queue[0].group_by_id('nonrigid')[0]))
        rigid_mols = css.run_queue[0].group_by_id('rigid')[0]
        if rigid_mols:
            sim.add(lmps.Group(rig_group_name, 'id', rigid_mols))

        # create the description of the molecular dynamics simulation
        if type(mdp.get('timestep')) == list:

            sim.add(lmps.OutputSettings(thermo=mdp.get('thermo'),
                                        dump={'filename': os.path.join(sim_folder, str(l) + '.md.dump'),
                                              'freq': int(mdp.get('dump'))}))

            for it, (t, lng) in enumerate(zip(mdp.get('timestep'), mdp.get('length'))):

                sim.add(lmps.Velocity(style='create'))
                # adding "run 0" line before velocities rescale for correct temperature init of the
                # system with rigid molecules
                if rigid_mols:
                    sim.add_custom('run 0')
                    sim.add(lmps.Velocity(style='scale'))

                sim.add_md(lmps.MolecularDynamics(name='main_fix_{}'.format(it),
                                                  group=nonrig_group_name if rigid_mols else 'all',
                                                  ensemble='npt',
                                                  timestep=t,
                                                  temperature=mdp.get('temp'),
                                                  pressure=mdp.get('pressure'),
                                                  run=False,
                                                  extra_keywords={'dilate': 'all'} if rigid_mols else {}))

                # create the second NVT fix for rigid molecules that cannot be put in NPT fix
                if rigid_mols:
                    sim.add(lmps.MolecularDynamics(name='rig_fix_{}'.format(it),
                                                   ensemble='rigid/nvt/small molecule',
                                                   timestep=t,
                                                   length=mdp.get('length'),
                                                   group=rig_group_name,
                                                   temperature=mdp.get('temp'),
                                                   pressure=mdp.get('pressure'),
                                                   run=False))
                sim.add_custom('fix        tether_fix_{} matrix spring tether 30.0 0.0 0.0 0.0 0.0'.format(it))

                sim.add_custom('run {:}\n'.format(lng))
                sim.add_custom('unfix main_fix_{:}'.format(it))
                sim.add_custom('unfix rig_fix_{:}'.format(it))
                sim.add_custom('unfix tether_fix_{:}'.format(it))

        else:
            sim.add_md(lmps.MolecularDynamics(name='main_fix',
                                              group=nonrig_group_name if rigid_mols else 'all',
                                              ensemble='npt',
                                              timestep=mdp.get('timestep'),
                                              temperature=mdp.get('temp'),
                                              pressure=mdp.get('pressure'),
                                              run=False,
                                              extra_keywords={'dilate': 'all'} if rigid_mols else {}))

            # create the second NVT fix for rigid molecules that cannot be put in NPT fix
            if rigid_mols:
                sim.add(lmps.MolecularDynamics(name='rig_fix',
                                               ensemble='rigid/nvt/small molecule',
                                               timestep=mdp.get('timestep'),
                                               length=mdp.get('length'),
                                               group=rig_group_name,
                                               temperature=mdp.get('temp'),
                                               pressure=mdp.get('pressure'),
                                               run=False))

            # add the "spring tether" fix to the geometrical center of the system to avoid system creep
            sim.add_custom('fix tether_fix matrix spring tether 30.0 0.0 0.0 0.0 0.0')
            sim.add(lmps.OutputSettings(thermo=mdp.get('thermo'),
                                        dump={'filename': os.path.join(sim_folder, str(l) + '.md.dump'),
                                              'freq': int(mdp.get('dump'))}))
            sim.add_custom('run {:}\n'.format(mdp.get('length')))

        # The input for correct simulations is set, starting LAMMPS:
        sim.run(prefix=[''])
        os.environ['OMP_NUM_THREADS'] = nm_treads

        # Updating the size of the fixed system from the MD simulations and saving the coordinates for the next MC
        # css.system.dim = sim.system.dim
        css.system = sim.system.copy()
        css.unwrap_gas()
        css.system.write_xyz(xyz_fname.format(l))

        mcp['Start_Type']['file_name'] = xyz_fname.format(l)
        mcp['Start_Type']['species'] = [1] + css.run_queue[-1].mc_sst.made_ins
        l += 1

    return sim.system if sim else None
Beispiel #9
0
def run(test=False):
    # we'll make a polystyrene monomer from the pysimm models database
    A = NbTMS(isomer="exoexo")
    # we'll instantiate a Dreiding forcefield object for use later
    f = forcefield.Dreiding()

    # the monomers do not have any charges, so we will derive partial charges using the gasteiger algorithm
    A.apply_charges(f, charges='gasteiger')

    # the buckingham potential isn't great at small distances, and therefore we use the LJ potential while growing the polymer
    A.pair_style = 'lj/cut'

    # run the polymer random walk tacticity method with 10 total repeat units
    polymer = random_walk_tacticity(A,
                                    20,
                                    forcefield=f,
                                    capped=True,
                                    tacticity='syndiotactic',
                                    rotation=180,
                                    errorCheck=False,
                                    sim=0)
    writeFileFormats(polymer, "polymer", unwrap=True)

    #quick opt of polymer
    lmps.quick_min(polymer, min_style='fire', etol=1.0e-4, maxiter=100000)

    # write a few different file formats
    polymer.unwrap()
    writeFileFormats(polymer, "polymer_fired")

    #pack multiple copies of polymer
    polymers = system.replicate(polymer, 8, density=0.005)
    #polymers = polymer
    writeFileFormats(polymers, "polymers")
    lmps.quick_min(polymers, min_style='fire', etol=1.0e-4, maxiter=100000)
    writeFileFormats(polymers, "polymers_fired")

    #quickmd
    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'
    }
    #nvt runs okay, but npt fails...need to add neigh_modify command to reneighbor more often during compression of npt step
    #lmps.quick_md(polymers, debug=True, **nvt_settings)
    #writeFileFormats(polymers,"polymers_nvt")
    #lmps.quick_md(polymers, debug=True, **npt_settings)
    #lmps.quick_md(polymers)
    #writeFileFormats(polymers,"polymers_npt")
    sim = lmps.Simulation(polymers, name='nptAndReneighbor', debug=True)
    sim.add_custom('neigh_modify delay 0')
    sim.add(lmps.Velocity(temperature=1000))
    sim.add_md(length=10000, ensemble='npt', temperature=1000, pressure=5000)
    sim.run()
    writeFileFormats(polymers, "polymers_npt")
    writeFileFormats(polymers, "polymers_npt_unwrapped", unwrap=True)

    #21-step equilibration
    equil(polymers, np=1, pmax=50000)
    writeFileFormats(polymers, "polymers_equil")
    polymers.unwrap()
    writeFileFormats(polymers, "polymers_equil_unwrap")