Exemplo n.º 1
0
def monomer_system(num_particles, density=0.8, seed=None):

    num_particles = num_particles
    L = pow(num_particles/density, 1./3.)
    box = (L, L, L)

    # Initialize the espresso system
    system         = espresso.System()
    if seed is not None:
        system.rng     = espresso.esutil.RNG(seed)
    else:
        system.rng     = espresso.esutil.RNG()
    system.bc      = espresso.bc.OrthorhombicBC(system.rng, box)
    system.skin    = skin
    nodeGrid       = espresso.tools.decomp.nodeGrid(MPI.COMM_WORLD.size)
    cellGrid       = espresso.tools.decomp.cellGrid(box, nodeGrid, rc, skin)
    system.storage = espresso.storage.DomainDecomposition(system, nodeGrid, cellGrid)

    def normal_v():
        return espresso.Real3D(system.rng.normal()*0.5, system.rng.normal()*0.5, system.rng.normal()*0.5)

    # Add the individual particles
    Xs = []
    pid = 0
    for i in range(num_particles):
        pos = system.bc.getRandomPos()
        v = espresso.Real3D(system.rng.normal(),system.rng.normal(),system.rng.normal())
        Xs.append([pid, pos, v])
        pid += 1
    system.storage.addParticles(Xs, 'id', 'pos', 'v')

    # Define capped LJ potential
    verletList = espresso.VerletList(system, cutoff=rc)
    LJCapped    = espresso.interaction.VerletListLennardJonesCapped(verletList)
    LJCapped.setPotential(type1=0, type2=0, potential=espresso.interaction.LennardJonesCapped(epsilon=epsilon, sigma=sigma, cutoff=rc, caprad=caprad_LJ))
    system.addInteraction(LJCapped)

    # Define integrator and StochasticVelocityRescaling thermostat
    integrator     = espresso.integrator.VelocityVerlet(system)
    thermostat = espresso.integrator.StochasticVelocityRescaling(system)
    thermostat.temperature = 1.0
    integrator.addExtension(thermostat)

    system.storage.decompose()

    return system, integrator, LJCapped, verletList, thermostat, num_particles
system.rng = espresso.esutil.RNG(54321)
system.bc = espresso.bc.OrthorhombicBC(system.rng, size)
system.skin = skin
comm = MPI.COMM_WORLD
nodeGrid = decomp.nodeGrid(comm.size)
cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin)
system.storage = espresso.storage.DomainDecomposition(system, nodeGrid,
                                                      cellGrid)

# add particles to the system and then decompose
for pid in range(num_particles):
    system.storage.addParticle(pid + 1, Real3D(x[pid], y[pid], z[pid]))
system.storage.decompose()

# Lennard-Jones with Verlet list
vl = espresso.VerletList(system, cutoff=rc + system.skin)
potTabLJ = espresso.interaction.Tabulated(itype=spline,
                                          filename=tabfileLJ,
                                          cutoff=rc)
potLJ = espresso.interaction.LennardJones(sigma=1.0,
                                          epsilon=1.0,
                                          cutoff=rc,
                                          shift=False)
if sys.argv.count("tlj") > 0:
    print('tabulated potential from file %s' % potTabLJ.filename)
    interLJ = espresso.interaction.VerletListTabulated(vl)
    interLJ.setPotential(type1=0, type2=0, potential=potTabLJ)
else:
    interLJ = espresso.interaction.VerletListLennardJones(vl)
    interLJ.setPotential(type1=0, type2=0, potential=potLJ)
system.addInteraction(interLJ)
Exemplo n.º 3
0
new_particles = []
mass = 1.0
type = 0
for pid in range(num_particles):
    pos = espresso.Real3D(x[pid], y[pid], z[pid])
    vel = espresso.Real3D(0, 0, 0)
    part = [pid, type, pos, vel, mass]
    new_particles.append(part)

system.storage.addParticles(new_particles, *props)
system.storage.decompose()

##########################################################################################

# interaction
vl = espresso.VerletList(system, cutoff=rc)
tabP = espresso.interaction.Tabulated(itype=1, filename='CG_CG.tab', cutoff=rc)
tabI = espresso.interaction.VerletListTabulated(vl)
tabI.setPotential(type1=0, type2=0, potential=tabP)
system.addInteraction(tabI)

##########################################################################################

# integrator
integrator = espresso.integrator.VelocityVerlet(system)
integrator.dt = timestep

# thermostat
lT = espresso.integrator.LangevinThermostat(system)
lT.gamma = 5.0
lT.temperature = 2.5
Exemplo n.º 4
0
def chains_x_system(num_chains,
                    monomers_per_chain,
                    num_X,
                    density=0.8,
                    seed=None):

    num_particles = num_chains * monomers_per_chain + num_X
    L = pow(num_particles / density, 1. / 3.)
    box = (L, L, L)

    # Initialize the espresso system
    system = espresso.System()
    if seed is not None:
        system.rng = espresso.esutil.RNG(seed)
    else:
        system.rng = espresso.esutil.RNG()
    system.bc = espresso.bc.OrthorhombicBC(system.rng, box)
    system.skin = skin
    nodeGrid = espresso.tools.decomp.nodeGrid(MPI.COMM_WORLD.size)
    cellGrid = espresso.tools.decomp.cellGrid(box, nodeGrid, rc, skin)
    system.storage = espresso.storage.DomainDecomposition(
        system, nodeGrid, cellGrid)

    def normal_v():
        return espresso.Real3D(system.rng.normal() * 0.5,
                               system.rng.normal() * 0.5,
                               system.rng.normal() * 0.5)

    # Add the chains
    chainFPL = espresso.FixedPairList(system.storage)
    pid = 0
    for i in range(num_chains):
        chain = []
        startpos = system.bc.getRandomPos()
        positions, bonds = espresso.tools.topology.polymerRW(
            pid, startpos, monomers_per_chain, bondlen)
        for k in range(monomers_per_chain):
            part = [pid + k, positions[k], normal_v()]
            chain.append(part)
        pid += monomers_per_chain
        system.storage.addParticles(chain, 'id', 'pos', 'v')
        chainFPL.addBonds(bonds)

    # Add the individual particles
    Xs = []
    for i in range(num_X):
        pos = system.bc.getRandomPos()
        v = espresso.Real3D(system.rng.normal(), system.rng.normal(),
                            system.rng.normal())
        Xs.append([pid, pos, v])
        pid += 1
    system.storage.addParticles(Xs, 'id', 'pos', 'v')

    # Define capped LJ potential
    verletList = espresso.VerletList(system, cutoff=rc)
    LJCapped = espresso.interaction.VerletListLennardJonesCapped(verletList)
    LJCapped.setPotential(type1=0,
                          type2=0,
                          potential=espresso.interaction.LennardJonesCapped(
                              epsilon=epsilon,
                              sigma=sigma,
                              cutoff=rc,
                              caprad=caprad_LJ))
    system.addInteraction(LJCapped)

    # Define capped FENE potential
    potFENE = espresso.interaction.FENECapped(K=K,
                                              r0=0.0,
                                              rMax=rMax,
                                              caprad=caprad_FENE)
    FENECapped = espresso.interaction.FixedPairListFENECapped(
        system, chainFPL, potFENE)
    system.addInteraction(FENECapped)

    # Define integrator and StochasticVelocityRescaling thermostat
    integrator = espresso.integrator.VelocityVerlet(system)
    thermostat = espresso.integrator.StochasticVelocityRescaling(system)
    thermostat.temperature = 1.0
    integrator.addExtension(thermostat)

    system.storage.decompose()

    return system, integrator, LJCapped, verletList, FENECapped, chainFPL, thermostat, num_particles