Пример #1
0
def cap_with_methyls(input_sst, ff):
    '''
        An utility method that implements capping of free ends of polymer chains with methyl 
        groups in all-atom forcefield representation
    '''
    # Let's cap the oligomer with the methyl (-CH3) group
    captypes = []
    for cpn in ['CG331', 'HGA3']:
        tmp = input_sst.particle_types.get(cpn)
        if tmp:
            cpt = tmp[0]
        else:
            cpt = ff.particle_types.get(cpn)[0].copy()
            input_sst.particle_types.add(cpt)
        captypes.append(cpt)

    for p in input_sst.particles:
        if p.linker is not None:
            if len(p.bonded_to) < 4:

                # assuming that the linker atom is sp3 hybridised C let's define the last non-occupied direction
                # of the tetrahedron
                dir = numpy.zeros(3)
                for p_ in p.bonded_to:
                    dir += numpy.array([p.x, p.y, p.z]) - numpy.array([p_.x, p_.y, p_.z])

                dir = dir / numpy.linalg.norm(dir)
                cap_c = system.Particle(x=p.x + 1.53 * dir[0], y=p.y + 1.53 * dir[1], z=p.z + 1.53 * dir[2],
                                        type=captypes[0])
                input_sst.add_particle_bonded_to(cap_c, p, f=ff)

                dir_h = numpy.array([1.0, 1.0, 1.0])
                dir_h[0] = -(dir_h[1] * dir[1] + dir_h[2] * dir[2]) / dir[0]
                dir_h = dir_h / numpy.linalg.norm(dir_h)

                dir_h2 = numpy.array([1.0, 1.0, -1.0])
                dir_h2[1] = (dir[2] / dir[0] - dir_h[2] / dir_h[0]) / (dir[1] / dir[0] - dir_h[1] / dir_h[0])
                dir_h2[0] = dir[2] / dir[0] - dir[1] * dir_h2[1] / dir[0]
                dir_h2 = dir_h2 / numpy.linalg.norm(dir_h2)

                stretch = 0.78
                input_sst.add_particle_bonded_to(system.Particle(x=cap_c.x + stretch * dir[0] + stretch * dir_h[0],
                                                                 y=cap_c.y + stretch * dir[1] + stretch * dir_h[1],
                                                                 z=cap_c.z + stretch * dir[2] + stretch * dir_h[2],
                                                                 type=captypes[1]), cap_c, f=ff)
                input_sst.add_particle_bonded_to(system.Particle(x=cap_c.x + stretch * dir[0] + stretch * dir_h2[0],
                                                                 y=cap_c.y + stretch * dir[1] + stretch * dir_h2[1],
                                                                 z=cap_c.z + stretch * dir[2] + stretch * dir_h2[2],
                                                                 type=captypes[1]), cap_c, f=ff)
                input_sst.add_particle_bonded_to(system.Particle(x=cap_c.x + stretch * dir[0] - stretch * dir_h2[0],
                                                                 y=cap_c.y + stretch * dir[1] - stretch * dir_h2[1],
                                                                 z=cap_c.z + stretch * dir[2] - stretch * dir_h2[2],
                                                                 type=captypes[1]), cap_c, f=ff)
    input_sst.objectify()
    input_sst.center(what='particles', at=[0.0, 0.0, 0.0], move_both=False)

    sim = lmps.Simulation(input_sst, log='capping_opt.log')
    sim.add_min(min_style='cg', name='min_cg', etol=1.0e-6, ftol=1.0e-6, maxiter=int(1e+6), maxeval=int(1e+7))
    sim.run()
Пример #2
0
def Cl():
    s = system.System()
    m = s.molecules.add(system.Molecule())
    f = forcefield.Dreiding()
    dreiding_Na_ = s.particle_types.add(f.particle_types.get('Cl')[0].copy())
    s.particles.add(system.Particle(type=dreiding_Na_, x=0, y=0, z=0, charge=-1, molecule=m))
    s.apply_forcefield(f)
    s.pair_style = 'lj/cut'

    lmps.quick_min(s, min_style='fire')
    return s
Пример #3
0
s = system.System()

# create new molecule in our system
m = s.molecules.add(system.Molecule())

# retrieve GAFF2 parameters
f = forcefield.Gaff2()

# get a copy of the c3 particle type object from GAFF
# get method returns a list, we need the first element
gaff_c3 = s.particle_types.add(f.particle_types.get('c3')[0].copy())

# we'll first make the carbon atom at the origin
# we'll include gasteiger charges later
c1 = s.particles.add(
    system.Particle(type=gaff_c3, x=0, y=0, z=0, charge=0, molecule=m))

# get hc particle type object from GAFF
gaff_hc = f.particle_types.get('hc')[0].copy()

# add hc particle type to system
s.particle_types.add(gaff_hc)

# now we'll add 4 hydrogen atoms bonded to our carbon atom
# these atoms will be placed randomly 1.5 angstroms from the carbon atom
# we'll optimize the structure using LAMMPS afterwords
# we supply the GAFF forcefield object so that bond and angle types can be added as well
h1 = s.add_particle_bonded_to(
    system.Particle(type=gaff_hc, charge=0, molecule=m), c1, f)
h2 = s.add_particle_bonded_to(
    system.Particle(type=gaff_hc, charge=0, molecule=m), c1, f)
Пример #4
0
monomer.set_charge()
print('\tRead monomer has charge of {:}q'.format(round(monomer.charge, 8)))
if abs(monomer.charge + 1) < 0.1:
    print('\tAdding SODIUM counterion to equilibrate the system chargewise')
    cntrion_tp = ff.particle_types.get('SOD')[0].copy()
    chrg = 1
elif abs(monomer.charge - 1) < 0.1:
    print('\tAdding CLORINE counterion to equilibrate the system chargewise')
    cntrion_tp = ff.particle_types.get('CLA')[0].copy()
    chrg = -1
else:
    cntrion_tp = None

if cntrion_tp:
    monomer.particle_types.add(cntrion_tp)
    monomer.particles.add(system.Particle(x=monomer.cog[0], y=monomer.cog[1], z=monomer.cog[2] + 5.0, type=cntrion_tp,
                                      charge=chrg, molecule=monomer.molecules[1]))

# -------------> Polymer construction and tacticity check <--------------
sngl_chain = random_walk(monomer, chain_len, forcefield=ff, density=0.01, print_to_screen='true', traj=False, unwrap=True)

if is_cap:
    cap_with_methyls(sngl_chain, ff)

# After polymerisation and possibly capping is done let's cleanup: remove all counterions and reshape the simulation
# box so that the chain is in the center of a cube with padding of 3 nm

sngl_chain.center(what='particles', at=[0.0, 0.0, 0.0], move_both=False)

if cntrion_tp:
    for p in sngl_chain.particles:
        if p.type.name == cntrion_tp.name:
Пример #5
0
def run(test=False):
    # we'll make a polyethylene monomer and a polystyrene monomer from the pysimm models database
    pe = pe_monomer()
    ps = ps_monomer()
    ba = ba_monomer()
    H20 = water_water()
    dise = dise_monomer()
    disg = disg_monomer()
    disi = disi_monomer()
    amide = amide_monomer()
    peg = peg_monomer()
    Na = pos_salt()
    Cl = neg_salt()

    # we'll instantiate a Dreiding forcefield object for use later
    f = forcefield.gaff2()

    # the monomers do not have any charges, so we will derive partial charges using the gasteiger algorithm
    pe.apply_charges(f, charges='gasteiger')
    ps.apply_charges(f, charges='gasteiger')
    #H20.apply_charges(f,charges = 'gasteiger')
    ba.apply_charges(f, charges='gasteiger')
    peg.apply_charges(f, charges='gasteiger')
    amide.apply_charges(f, charges='gasteiger')
    dise.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
    pe.pair_style = 'lj/cut'
    ps.pair_style = 'lj/cut'
    H20.pair_style = 'lj/cut'
    ba.pair_style = 'lj/cut'
    dise.pair_style = 'lj/cut'
    disg.pair_style = 'lj/cut'
    peg.pair_style = 'lj/cut'
    amide.pair_style = 'lj/cut'
    disi.pair_style = 'lj/cut'
    Na.pair_style = 'lj/cut'
    Cl.pair_style = 'lj/cut'

    ######## Heres the Paramaters you can edit ##########
    ##### Specifiy What Monomer that you are going to use and the frequency of each Monomer
    polist = [ba, amide, disg, disi, dise]
    monlist = [10, 80, 5, 4, 1]
    n_molecules = 50000  # Number of Water Molecules Try to keep it at 10,000

    ##Current Monomers available
    # PEG5 : peg
    # Butyl Acrylate : ba
    # amide monomer: amide
    # Ethelyne: pa
    # Polystyrene: ps
    # MethylAcrylate: pmma
    # disulfideG: disg
    # disulfideI: disi
    # disulfideE: dise
    ####################################################################################

    pattern = shuffle(monlist, polist)

    # run the copolymer random walk method with 10 total repeat units, using an alternating pattern
    z = np.ones(len(pattern))
    setter = []
    for elem in range(0, len(z)):
        setter.append(int(z[elem]))
    print(setter)
    polymer = copolymer(pattern, len(pattern), pattern=setter, forcefield=f)

    polymer.write_xyz('polymernonsolvated.xyz')

    charge = 0
    for pb in polymer.particles:
        charge = charge + pb.charge
    print("The System has: " + str(charge) + " charge")

    numSa = round(charge)
    if charge < 0:
        salt = 'Na'
        charg = +1
    else:
        salt = 'Cl'
        charg = -1

    partition = n_molecules / (abs(numSa) + 1)
    if round(charge) == 0:
        system.replicate([H20], n_molecules, s_=polymer, density=0.6)
    else:
        for iters in range(0, abs(numSa) + 1):

            system.replicate([H20],
                             abs(int(partition)),
                             s_=polymer,
                             density=0.6)
            if iters == abs(numSa):
                lmps.quick_min(polymer, min_style='sd')
                break
            m = polymer.molecules.add(system.Molecule())
            dreiding_salt_ = polymer.particle_types.add(
                f.particle_types.get(salt)[0].copy())
            polymer.particles.add(
                system.Particle(type=dreiding_salt_,
                                x=polymer.dim.dx / 2,
                                y=polymer.dim.dy / 2,
                                z=polymer.dim.dz / 2,
                                charge=charg,
                                molecule=m))
            lmps.quick_min(polymer, min_style='sd')

    charge = 0
    for pb in polymer.particles:
        charge = charge + pb.charge
    print("The System has: " + str(charge) + " charge")

    if charge < 0:
        salt = 'Na'
        charg = +1
    else:
        salt = 'Cl'
        charg = -1

    m = polymer.molecules.add(system.Molecule())
    dreiding_salt_ = polymer.particle_types.add(
        f.particle_types.get(salt)[0].copy())
    polymer.particles.add(
        system.Particle(type=dreiding_salt_,
                        x=polymer.dim.dx / 2,
                        y=polymer.dim.dy / 2,
                        z=polymer.dim.dz / 2,
                        charge=-charge,
                        molecule=m))
    lmps.quick_min(polymer, min_style='sd')

    charge = 0
    for pb in polymer.particles:
        charge = charge + pb.charge
    print("The System has: " + str(charge) + " charge")

    # write a few different file formats
    polymer.write_xyz('polymersolvated.xyz')
    # polymer.write_yaml('polymer.yaml')
    polymer.write_lammps('polymer.lmps')
Пример #6
0
def run(test=False):
    # create empty system
    print('Example progress: Creating an empty system...')
    s = system.System()

    # create new molecule in our system
    print(
        'Example progress: Adding an empty molecule container to our system...'
    )
    m = s.molecules.add(system.Molecule())

    # retrieve GAFF2 parameters
    print('Example progress: Retrieving Dreiding force field parameters...')
    f = forcefield.Gaff2()
    s.forcefield = f.name

    # get a copy of the c3 particle type object from GAFF
    # get method returns a list, we need the first element
    gaff_c3 = s.particle_types.add(f.particle_types.get('c3')[0].copy())

    # get hc particle type object from GAFF
    gaff_hc = s.particle_types.add(f.particle_types.get('hc')[0].copy())

    # we'll first make the carbon atom at the origin
    # we'll include gasteiger charges later
    print('Example progress: Adding carbon atom at origin...')
    c1 = s.particles.add(
        system.Particle(type=gaff_c3, x=0, y=0, z=0, charge=0, molecule=m))

    # now we'll add 4 hydrogen atoms bonded to our carbon atom
    # these atoms will be placed randomly 1.5 angstroms from the carbon atom
    # we'll optimize the structure using LAMMPS afterwords
    # we supply the GAFF forcefield object so that bond and angle types can be added as well
    print(
        'Example progress: Adding 4 hydrogen atoms at random positions bonded to the carbon atom...'
    )
    h1 = s.add_particle_bonded_to(
        system.Particle(type=gaff_hc, charge=0, molecule=m), c1, f)
    h2 = s.add_particle_bonded_to(
        system.Particle(type=gaff_hc, charge=0, molecule=m), c1, f)
    h3 = s.add_particle_bonded_to(
        system.Particle(type=gaff_hc, charge=0, molecule=m), c1, f)
    h4 = s.add_particle_bonded_to(
        system.Particle(type=gaff_hc, charge=0, molecule=m), c1, f)

    # let's add gasteiger charges
    print('Example progress: Deriving Gasteiger charges...')
    s.apply_charges(f, charges='gasteiger')

    # right now there is no simulation box defined
    # we'll define a box surrounding our methane molecule with a 10 angstrom padding
    print(
        'Example progress: Constructing Simulation box surrounding our new molecule...'
    )
    s.set_box(padding=10)

    # before we optimize our structure, LAMMPS needs to know what type of
    # pair, bond, and angle interactions we are using
    # these are determined by the forcefield being used
    s.pair_style = 'lj'
    s.bond_style = 'harmonic'
    s.angle_style = 'harmonic'

    # we'll perform energy minimization using the fire algorithm in LAMMPS
    print('Example progress: Optimizing structure using LAMMPS...')
    lmps.quick_min(s,
                   min_style='fire',
                   name='fire_min',
                   etol=1e-10,
                   ftol=1e-10)

    # write xyz, YAML, LAMMPS data, and chemdoodle json files
    print('Example progress: Saving structure to files...')
    s.write_xyz('methane.xyz')
    s.write_yaml('methane.yaml')
    s.write_lammps('methane.lmps')
    s.write_chemdoodle_json('methane.json')

    print('Example progress: Complete!')
Пример #7
0
    f.write(
        str(len(df)) + '\nThis is the place for the header of your XYZ file\n')
    df[['type', 'x', 'y', 'z']].to_csv(f, sep='\t', header=False, index=False)

# Initial setup of the pysimm System with MOF
s = system.System()
tmp = resp.text.encode('ascii', 'ignore').split('\n')
for line in tmp[1:-1]:
    data = line.split()
    tag, ptype, x, y, z, restof = data[:6]
    elem = re.sub('\d+', '', ptype)
    bonds = map(int, data[6:])
    p = system.Particle(tag=int(tag),
                        elem=elem,
                        type_name=ptype,
                        x=float(x),
                        y=float(y),
                        z=float(z),
                        bonds=bonds)
    s.particles.add(p)

for p in s.particles:
    for pb in p.bonds:
        if p.tag < pb:
            s.bonds.add(system.Bond(a=p, b=s.particles[pb]))
s.add_particle_bonding()

# Assign Dreiding forcefield parameters to the atoms of the structure
f = forcefield.Dreiding()
o_3 = s.particle_types.add(f.particle_types.get('O_3')[0].copy())
o_r = s.particle_types.add(f.particle_types.get('O_R')[0].copy())