Пример #1
0
def generate_system(add_particles_array):
    rc = 2.5
    skin = 0.3
    timestep = 0.005
    temperature = 1.0
    comm = MPI.COMM_WORLD

    particles_per_direction = 64
    x, y, z, Lx, Ly, Lz, vx, vy, vz = generate_particles(
        particles_per_direction)

    num_particles = len(x)
    density = num_particles / (Lx * Ly * Lz)
    size = (Lx, Ly, Lz)

    system = espressopp.System()
    system.rng = espressopp.esutil.RNG()
    system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
    system.skin = skin
    nodeGrid = decomp.nodeGrid(comm.size, size, rc, skin)
    cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin)
    system.storage = espressopp.storage.DomainDecomposition(
        system, nodeGrid, cellGrid)

    if add_particles_array:

        tstart = time.time()
        props = [
            'id', 'type', 'mass', 'posx', 'posy', 'posz', 'vx', 'vy', 'vz'
        ]
        ids = np.arange(1, num_particles + 1)
        types = np.zeros(num_particles)
        mass = np.ones(num_particles)
        new_particles = np.stack((ids, types, mass, x, y, z, vx, vy, vz),
                                 axis=-1)
        tprep = time.time() - tstart

        tstart = time.time()
        system.storage.addParticlesArray(new_particles, *props)
        tadd = time.time() - tstart

    else:

        tstart = time.time()
        props = ['id', 'type', 'mass', 'pos', 'v']
        new_particles = []
        for i in range(num_particles):
            new_particles.append([
                i + 1, 0, 1.0,
                Real3D(x[i], y[i], z[i]),
                Real3D(vx[i], vy[i], vz[i])
            ])
        tprep = time.time() - tstart

        tstart = time.time()
        system.storage.addParticles(new_particles, *props)
        tadd = time.time() - tstart

    return num_particles, tprep, tadd
Пример #2
0
def generate_system():
    rc = 2.5
    skin = 0.3
    timestep = 0.005
    temperature = 1.0
    comm = MPI.COMM_WORLD
    density = num_particles / (Lx * Ly * Lz)
    size = (Lx, Ly, Lz)

    system = espressopp.System()
    system.rng = espressopp.esutil.RNG()
    system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
    system.skin = skin
    nodeGrid = decomp.nodeGrid(comm.size, size, rc, skin)
    cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin)
    system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid)

    return system
Пример #3
0
#defaults, types, masses, charges, atomtypeparameters, bondtypes, bondtypeparams, angletypes, angletypeparams, exclusions, x, y, z, vx, vy, vz, Lx, Ly, Lz = gromacs.read(grofile,topfile)
num_particles = len(x)

density = num_particles / (Lx * Ly * Lz)
size = (Lx, Ly, Lz)
print size

sys.stdout.write('Setting up simulation ...\n')
system = espressopp.System()
system.rng = espressopp.esutil.RNG()
system.bc = espressopp.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 = espressopp.storage.DomainDecomposition(
    system, nodeGrid, cellGrid)

# setting up GROMACS interaction stuff
# create a force capped Lennard-Jones interaction that uses a verlet list
verletlist = espressopp.VerletList(system, rc)
interaction = espressopp.interaction.VerletListLennardJonesGromacs(verletlist)

# add particles to the system and then decompose
props = ['id', 'pos', 'v', 'type', 'mass', 'q']
allParticles = []
for pid in range(num_particles):
    part = [
        pid + 1,
        Real3D(x[pid], y[pid], z[pid]),
Пример #4
0
# number of AT particles
num_particles = len(x)

# set up the system
sys.stdout.write('Setting up simulation ...\n')
density = num_particles / (Lx * Ly * Lz)
size = (Lx, Ly, Lz)

system = espressopp.System()
system.rng = espressopp.esutil.RNG()
system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
system.skin = skin

comm = MPI.COMM_WORLD
nodeGrid = decomp.nodeGrid(comm.size)
cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin)

# (H-)AdResS domain decomposition
system.storage = espressopp.storage.DomainDecompositionAdress(system, nodeGrid, cellGrid)


# prepare AT particles
allParticlesAT = []
allParticles = []
tuples = []
for pidAT in range(num_particles):
    allParticlesAT.append([pidAT, # add here these particles just temporarily
                         Real3D(x[pidAT], y[pidAT], z[pidAT]), # position
                         Real3D(vx[pidAT], vy[pidAT], vz[pidAT]), # velocity
                         Real3D(0, 0, 0), # force
                         1, 1.0, 1]) # type, mass, is AT particle
Пример #5
0
num_particles_CG = len(x) // 3
density = num_particles_AT / (Lx * Ly * Lz)
size = (Lx, Ly, Lz)

#####################
#  3. set up the system  #
#####################

print('Setting up system...')
# system, boundary conditions, skin, communicator, node & cell grids
system = espressopp.System()
system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
system.skin = skin
comm = MPI.COMM_WORLD
nodeGrid = decomp.nodeGrid(comm.size)
cellGrid = decomp.cellGrid(size, nodeGrid, interaction_cutoff_verletlist_at,
                           skin)

# random number generator
rng = espressopp.esutil.RNG()
rng.seed(42)
system.rng = rng

# AdResS domain decomposition
system.storage = espressopp.storage.DomainDecompositionAdress(
    system, nodeGrid, cellGrid)

##########################
#  4. add particles to system  #
##########################

print('Adding particles and tuples...')
Пример #6
0
        coord.append( Real3D(x,y,z) )
        vel.append( Real3D(vx,vy,vz) )

density = num_particles / (Lx * Ly * Lz)
box     = (Lx, Ly, Lz)

######################################################################
sys.stdout.write('Setting up simulation ...\n')
system = espressopp.System()
system.rng = espressopp.esutil.RNG()
system.bc = espressopp.bc.OrthorhombicBC(system.rng, box)
system.skin = skin

comm = MPI.COMM_WORLD
nodeGrid = decomp.nodeGrid(comm.size,box,rc,skin)
cellGrid = decomp.cellGrid(box, nodeGrid, rc, skin)

system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid)
######################################################################

# add particles to the system and then decompose
props = ['id', 'type', 'pos', 'v', 'mass']
new_particles = []
type = 0
mass = 1.0
for pid in range(num_particles):
    part = [pid, type, coord[pid], vel[pid], mass]
    new_particles.append(part)

system.storage.addParticles(new_particles, *props)
system.storage.decompose()
    coord.append( Real3D(x,y,z) )
    vel.append( Real3D(vx,vy,vz) )

density = num_particles / (Lx * Ly * Lz)
box     = (Lx, Ly, Lz)

######################################################################
sys.stdout.write('Setting up simulation ...\n')
system = espressopp.System()
system.rng = espressopp.esutil.RNG()
system.bc = espressopp.bc.OrthorhombicBC(system.rng, box)
system.skin = skin

comm = MPI.COMM_WORLD
nodeGrid = decomp.nodeGrid(comm.size)
cellGrid = decomp.cellGrid(box, nodeGrid, rc, skin)

system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid)
######################################################################

# add particles to the system and then decompose
props = ['id', 'type', 'pos', 'v', 'mass']
new_particles = []
type = 0
mass = 1.0
for pid in range(num_particles):
  part = [pid, type, coord[pid], vel[pid], mass]
  new_particles.append(part)
  
system.storage.addParticles(new_particles, *props)
system.storage.decompose()
Пример #8
0
# repeat simulation twice, with and without tabulated potential
for tabulation in [True, False]:
    if tabulation: w = ''
    else: w = 'out'
    print 'Running simulation with%0s tabulated potentials' % w

    print 'Setting up ...'
    system = espressopp.System()
    system.rng = espressopp.esutil.RNG(54321)
    system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
    system.skin = skin

    comm = MPI.COMM_WORLD

    nodeGrid = decomp.nodeGrid(comm.size, size, rc, skin)
    cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin, halfCellInt)
    #nodeGrid = Int3D(1, 1, comm.size)
    #cellGrid = Int3D(
    #calcNumberCells(size[0], nodeGrid[0], rc),
    #calcNumberCells(size[1], nodeGrid[1], rc),
    #calcNumberCells(size[2], nodeGrid[2], rc)
    #)
    system.storage = espressopp.storage.DomainDecomposition(
        system, nodeGrid, cellGrid, halfCellInt)

    # 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
Пример #9
0
    def test_PIAdResS(self):
        print 'param =', self.param

        constkinmass = self.param['constkinmass']
        PILE = self.param['PILE']
        realkinmass = self.param['realkinmass']
        centroidthermostat = self.param['centroidthermostat']
        KTI = self.param['KTI']
        speedupInterAtom = self.param['speedupInterAtom']
        speedupFreezeRings = self.param['speedupFreezeRings']
        spherical_adress = self.param['spherical_adress']
        nb_forcefield_setup = self.param['nb_forcefield_setup']
        energy_before = self.param['energy_before']
        energy_after = self.param['energy_after']

        steps = 10
        timestep_short = 0.001 / 16.0
        multiplier_short_to_medium = 4
        multiplier_medium_to_long = 4
        interaction_cutoff = 0.84
        potential_cutoff = 0.78
        skin = 0.1
        gamma = 0.0
        temp = 2.50266751
        if KTI:
            ex_size = 100.0
        else:
            ex_size = 1.0
        hy_size = 1.5
        nTrotter = 4
        clmassmultiplier = 100.0
        PILElambda = 0.0
        CMDparameter = 1.0

        tabFEC_H = "FEC_H.dat"
        tabFEC_O = "FEC_O.dat"
        tabTHDF_H = "ThdForce_H.dat"
        tabTHDF_O = "ThdForce_O.dat"
        tabAngle = "tableESP_angle.dat"
        tabBondHH = "tableESP_bondHH.dat"
        tabBondOH = "tableESP_bondOH.dat"
        tabHW_HW = "tableESP_HW_HW.dat"
        tabHW_OW = "tableESP_HW_OW.dat"
        tabOW_OW = "tableESP_OW_OW.dat"

        pid, types, x, y, z, vx, vy, vz, Lx, Ly, Lz = espressopp.tools.readxyz(
            "input_test.xyz")
        masses = []
        for item in types:
            if item == 1:
                masses.append(15.9994)
            else:
                masses.append(1.008)

        num_Trotter_beads = len(x)
        num_atoms = len(x) / nTrotter
        size = (Lx, Ly, Lz)

        system = espressopp.System()
        system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
        system.skin = skin
        comm = MPI.COMM_WORLD
        nodeGrid = decomp.nodeGrid(comm.size)
        cellGrid = decomp.cellGrid(size, nodeGrid, interaction_cutoff, skin)
        system.rng = espressopp.esutil.RNG()
        system.storage = espressopp.storage.DomainDecompositionAdress(
            system, nodeGrid, cellGrid)

        props = ['id', 'pos', 'v', 'f', 'pib', 'type', 'mass', 'adrat']
        allParticlesAT = []
        allParticles = []
        tuples = []

        for pid_trotter in range(num_Trotter_beads):
            allParticlesAT.append([
                pid_trotter + 1,
                Real3D(x[pid_trotter], y[pid_trotter], z[pid_trotter]),
                Real3D(vx[pid_trotter], vy[pid_trotter], vz[pid_trotter]),
                Real3D(0, 0, 0), pid_trotter % nTrotter + 1,
                types[pid_trotter], masses[pid_trotter], 1
            ])
        for pid_atom in range(num_atoms):
            tmptuple = [pid_atom + num_Trotter_beads + 1]
            for pid_trotter in range(nTrotter):
                pid = pid_atom * nTrotter + pid_trotter
                tmptuple.append((allParticlesAT[pid])[0])
            firstParticleId = tmptuple[1]
            cmp = allParticlesAT[firstParticleId - 1][1]
            cmv = allParticlesAT[firstParticleId - 1][2]
            allParticles.append([
                pid_atom + num_Trotter_beads + 1,
                Real3D(cmp[0], cmp[1], cmp[2]),
                Real3D(cmv[0], cmv[1], cmv[2]),
                Real3D(0, 0, 0), 0, types[pid_atom * nTrotter],
                masses[pid_atom * nTrotter], 0
            ])
            for pid_trotter in range(nTrotter):
                pid = pid_atom * nTrotter + pid_trotter
                allParticles.append([(allParticlesAT[pid])[0],
                                     (allParticlesAT[pid])[1],
                                     (allParticlesAT[pid])[2],
                                     (allParticlesAT[pid])[3],
                                     (allParticlesAT[pid])[4],
                                     (allParticlesAT[pid])[5],
                                     (allParticlesAT[pid])[6],
                                     (allParticlesAT[pid])[7]])
            tuples.append(tmptuple)

        system.storage.addParticles(allParticles, *props)
        ftpl = espressopp.FixedTupleListAdress(system.storage)
        ftpl.addTuples(tuples)
        system.storage.setFixedTuplesAdress(ftpl)
        system.storage.decompose()

        bondsOH = []
        bondsHH = []
        for part in range(num_atoms / 3):
            bondsOH.append((num_Trotter_beads + 1 + 3 * part,
                            num_Trotter_beads + 1 + 3 * part + 1))
            bondsOH.append((num_Trotter_beads + 1 + 3 * part,
                            num_Trotter_beads + 1 + 3 * part + 2))
            bondsHH.append((num_Trotter_beads + 1 + 3 * part + 1,
                            num_Trotter_beads + 1 + 3 * part + 2))
        fplOH = espressopp.FixedPairList(system.storage)
        fplHH = espressopp.FixedPairList(system.storage)
        fplOH.addBonds(bondsOH)
        fplHH.addBonds(bondsHH)

        angles = []
        for part in range(num_atoms / 3):
            angles.append((num_Trotter_beads + 1 + 3 * part + 1,
                           num_Trotter_beads + 1 + 3 * part,
                           num_Trotter_beads + 1 + 3 * part + 2))
        ftl = espressopp.FixedTripleList(system.storage)
        ftl.addTriples(angles)

        vl = espressopp.VerletListAdress(system,
                                         cutoff=interaction_cutoff,
                                         adrcut=interaction_cutoff,
                                         dEx=ex_size,
                                         dHy=hy_size,
                                         adrCenter=[Lx / 2, Ly / 2, Lz / 2],
                                         exclusionlist=bondsOH + bondsHH,
                                         sphereAdr=spherical_adress)

        if nb_forcefield_setup == 1:
            interNB = espressopp.interaction.VerletListPIadressTabulatedLJ(
                vl, ftpl, nTrotter, speedupInterAtom)
        elif nb_forcefield_setup == 2:
            interNB = espressopp.interaction.VerletListPIadressNoDriftTabulated(
                vl, ftpl, nTrotter, speedupInterAtom)
        elif nb_forcefield_setup == 3:
            interNB = espressopp.interaction.VerletListPIadressTabulated(
                vl, ftpl, nTrotter, speedupInterAtom)
        else:
            raise ValueError(
                "Wrong nb_forcefield_setup integer (only 1,2,3 accepted.")
        potOOqm = espressopp.interaction.Tabulated(itype=3,
                                                   filename=tabOW_OW,
                                                   cutoff=potential_cutoff)
        potHOqm = espressopp.interaction.Tabulated(itype=3,
                                                   filename=tabHW_OW,
                                                   cutoff=potential_cutoff)
        potHHqm = espressopp.interaction.Tabulated(itype=3,
                                                   filename=tabHW_HW,
                                                   cutoff=potential_cutoff)
        if nb_forcefield_setup == 1:
            interNB.setPotentialQM(type1=1, type2=1, potential=potOOqm)
            interNB.setPotentialQM(type1=1, type2=0, potential=potHOqm)
            interNB.setPotentialQM(type1=0, type2=0, potential=potHHqm)
            potOOcl = espressopp.interaction.LennardJones(
                epsilon=temp,
                sigma=0.25,
                shift='auto',
                cutoff=1.122462048309373 * 0.25)
            interNB.setPotentialCL(type1=1, type2=1, potential=potOOcl)
        elif nb_forcefield_setup == 2:
            interNB.setPotential(type1=1, type2=1, potential=potOOqm)
            interNB.setPotential(type1=1, type2=0, potential=potHOqm)
            interNB.setPotential(type1=0, type2=0, potential=potHHqm)
        elif nb_forcefield_setup == 3:
            interNB.setPotentialQM(type1=1, type2=1, potential=potOOqm)
            interNB.setPotentialQM(type1=1, type2=0, potential=potHOqm)
            interNB.setPotentialQM(type1=0, type2=0, potential=potHHqm)
            interNB.setPotentialCL(type1=1, type2=1, potential=potOOqm)
            interNB.setPotentialCL(type1=1, type2=0, potential=potHOqm)
            interNB.setPotentialCL(type1=0, type2=0, potential=potHHqm)
        system.addInteraction(interNB)

        potBondHH = espressopp.interaction.Tabulated(itype=3,
                                                     filename=tabBondHH)
        potBondOH = espressopp.interaction.Tabulated(itype=3,
                                                     filename=tabBondOH)
        interBondedHH = espressopp.interaction.FixedPairListPIadressTabulated(
            system, fplHH, ftpl, potBondHH, nTrotter, speedupInterAtom)
        interBondedOH = espressopp.interaction.FixedPairListPIadressTabulated(
            system, fplOH, ftpl, potBondOH, nTrotter, speedupInterAtom)
        system.addInteraction(interBondedHH)
        system.addInteraction(interBondedOH)

        potAngle = espressopp.interaction.TabulatedAngular(itype=3,
                                                           filename=tabAngle)
        interAngle = espressopp.interaction.FixedTripleListPIadressTabulatedAngular(
            system, ftl, ftpl, potAngle, nTrotter, speedupInterAtom)
        system.addInteraction(interAngle)

        integrator = espressopp.integrator.PIAdressIntegrator(
            system=system,
            verletlist=vl,
            timestep=timestep_short,
            sSteps=multiplier_short_to_medium,
            mSteps=multiplier_medium_to_long,
            nTrotter=nTrotter,
            realKinMass=realkinmass,
            constKinMass=constkinmass,
            temperature=temp,
            gamma=gamma,
            centroidThermostat=centroidthermostat,
            CMDparameter=CMDparameter,
            PILE=PILE,
            PILElambda=PILElambda,
            CLmassmultiplier=clmassmultiplier,
            speedup=speedupFreezeRings,
            KTI=KTI)

        if not KTI:
            fec = espressopp.integrator.FreeEnergyCompensation(
                system, center=[Lx / 2, Ly / 2, Lz / 2], ntrotter=nTrotter)
            fec.addForce(itype=3, filename=tabFEC_O, type=1)
            fec.addForce(itype=3, filename=tabFEC_H, type=0)
            integrator.addExtension(fec)
            thdf = espressopp.integrator.TDforce(system, vl)
            thdf.addForce(itype=3, filename=tabTHDF_O, type=1)
            thdf.addForce(itype=3, filename=tabTHDF_H, type=0)
            integrator.addExtension(thdf)

        if KTI:
            for i in range(1, num_Trotter_beads + num_atoms + 1):
                system.storage.modifyParticle(i, 'lambda_adrd', 0.0)
                system.storage.modifyParticle(i, 'lambda_adr', 0.0)
                system.storage.modifyParticle(
                    i, 'varmass',
                    clmassmultiplier * system.storage.getParticle(i).mass)
            system.storage.decompose()

        espressopp.tools.AdressDecomp(system, integrator)

        Eb = interBondedOH.computeEnergy() + interBondedHH.computeEnergy()
        EAng = interAngle.computeEnergy()
        ELj = interNB.computeEnergy()
        Ek = integrator.computeKineticEnergy()
        EPI = integrator.computeRingEnergy()
        if KTI == False:
            Ecorr = fec.computeCompEnergy() + thdf.computeTDEnergy()
        else:
            Ecorr = 0.0
        energy_before_thistest = Ek + Eb + EAng + ELj + EPI + Ecorr

        integrator.run(steps)

        Eb = interBondedOH.computeEnergy() + interBondedHH.computeEnergy()
        EAng = interAngle.computeEnergy()
        ELj = interNB.computeEnergy()
        Ek = integrator.computeKineticEnergy()
        EPI = integrator.computeRingEnergy()
        if KTI == False:
            Ecorr = fec.computeCompEnergy() + thdf.computeTDEnergy()
        else:
            Ecorr = 0.0
        energy_after_thistest = Ek + Eb + EAng + ELj + EPI + Ecorr

        self.assertAlmostEqual(energy_before_thistest, energy_before, places=5)
        self.assertAlmostEqual(energy_after_thistest, energy_after, places=5)
Пример #10
0
num_Trotter_beads = len(x)  # total number of Trotter beads in the system
num_atoms = len(x) / nTrotter  # total number of atoms in the system
size = (Lx, Ly, Lz)  # size

#####################
#  3. set up the system  #
#####################

print 'Setting up system...'
# System, boundary conditions, skin, communicator, node & cell grids
system = espressopp.System()
system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
system.skin = skin
comm = MPI.COMM_WORLD
nodeGrid = decomp.nodeGrid(comm.size)
cellGrid = decomp.cellGrid(size, nodeGrid, interaction_cutoff, skin)

# Random number generator
rng = espressopp.esutil.RNG()
rng.seed(42)
system.rng = rng

# AdResS domain decomposition
system.storage = espressopp.storage.DomainDecompositionAdress(
    system, nodeGrid, cellGrid)

##########################
#  4. add particles to system  #
##########################

print 'Adding particles and tuples...'