def setUp(self):
        super(TestCaseExchangeReaction, self).setUp()
        import logging
        # 0-1-2-3-2-1-2-3-2-1-0
        particle_list = [
            (3, 0, espressopp.Real3D(3.0, 2.0, 2.0), 2, 1),
            (4, 1, espressopp.Real3D(3.2, 2.0, 2.0), 2, 0),
            (5, 2, espressopp.Real3D(3.4, 2.0, 2.0), 2, 2),
            (6, 3, espressopp.Real3D(3.6, 2.0, 2.0), 3, 3),
            (7, 2, espressopp.Real3D(3.8, 2.0, 2.0), 4, 2),
            (8, 1, espressopp.Real3D(4.0, 2.0, 2.0), 4, 0),
            (9, 2, espressopp.Real3D(4.2, 2.0, 2.0), 4, 2),
            (10, 3, espressopp.Real3D(4.4, 2.0, 2.0), 5, 3),
            (11, 2, espressopp.Real3D(4.6, 2.0, 2.0), 6, 2),
            (12, 1, espressopp.Real3D(4.8, 2.0, 2.0), 6, 0),
            (13, 0, espressopp.Real3D(5.0, 2.0, 2.0), 6, 2),
            (14, 4, espressopp.Real3D(4.2, 1.8, 2.0), 7, 4),
        ]
        self.system.storage.addParticles(particle_list, *self.part_prop)
        self.system.storage.decompose()
        # ('id', 'type', 'pos', 'res_id', 'state')

        self.fpl_static = espressopp.FixedPairList(self.system.storage)
        self.ftl_static = espressopp.FixedTripleList(self.system.storage)
        self.ftl123 = espressopp.FixedTripleList(self.system.storage)
        self.ftl232 = espressopp.FixedTripleList(self.system.storage)
        self.fpl_chem = espressopp.FixedPairList(self.system.storage)

        self.dynamic_exclude = espressopp.DynamicExcludeList(self.integrator)
        self.dynamic_exclude.observe_tuple(self.fpl_static)
        self.dynamic_exclude.observe_tuple(self.fpl_chem)
        self.dynamic_exclude.observe_triple(self.ftl_static)
        self.dynamic_exclude.observe_triple(self.ftl123)
        self.dynamic_exclude.observe_triple(self.ftl232)
        self.dynamic_exclude.observe_tuple(self.fpl_chem)

        self.fpl_static.addBonds([(3, 4), (4, 5), (7, 8), (8, 9), (11, 12),
                                  (12, 13)])
        self.topology_manager.observe_tuple(self.fpl_static)

        self.ftl_static.addTriples([(3, 4, 5), (7, 8, 9), (11, 12, 13)])

        self.ftl123.addTriples([(4, 5, 6), (6, 7, 8), (8, 9, 10),
                                (10, 11, 12)])
        self.topology_manager.register_triplet(self.ftl123, 1, 2, 3)

        self.ftl232.addTriples([(5, 6, 7), (9, 10, 11)])
        self.topology_manager.register_triplet(self.ftl232, 2, 3, 2)

        self.fpl_chem.addBonds([(5, 6), (6, 7), (9, 10), (10, 11)])
        self.topology_manager.register_tuple(self.fpl_chem, 2, 3)
        self.topology_manager.initialize_topology()
        self.dynamic_exclude.update()
    def setUp(self):
        super(TestCaseRemoveNeighbourBond, self).setUp()
        particle_list = [
            (3, 3, espressopp.Real3D(3.0, 2.0, 2.0), 2, 1),
            (4, 4, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1),
            (5, 4, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1),
            (6, 3, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1),
            (7, 4, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1),
        ]
        self.system.storage.addParticles(particle_list, *self.part_prop)
        self.system.storage.decompose()

        self.fpl23 = espressopp.FixedPairList(self.system.storage)
        self.fpl24 = espressopp.FixedPairList(self.system.storage)
        self.fpl34 = espressopp.FixedPairList(self.system.storage)

        self.ftl234 = espressopp.FixedTripleList(self.system.storage)
        self.ftl234.addTriples([(2, 3, 4)])

        self.fpl23.addBonds([(2, 3)])
        self.fpl24.addBonds([(2, 7)])
        self.fpl34.addBonds([(3, 4), (3, 5), (4, 6)])

        self.topology_manager.register_tuple(self.fpl24, 2, 4)
        self.topology_manager.register_tuple(self.fpl34, 3, 4)
        self.topology_manager.register_tuple(self.fpl23, 2, 3)
        self.topology_manager.register_triplet(self.ftl234, 2, 3, 4)

        self.topology_manager.initialize_topology()
 def test_angular_harmonic(self):
     ftl_lambda = espressopp.FixedTripleListLambda(self.system.storage)
     ftl_lambda.addTriples([(1, 2, 3)])
     ftl = espressopp.FixedTripleList(self.system.storage)
     ftl.addTriples([(1, 2, 3)])
     harmonic = espressopp.interaction.AngularHarmonic()
     interactionLambda = espressopp.interaction.FixedTripleListLambdaAngularHarmonic(
         self.system, ftl_lambda, harmonic)
     interaction = espressopp.interaction.FixedTripleListAngularHarmonic(
         self.system, ftl, harmonic)
     self.assertAlmostEqual(interaction.computeEnergy(),
                            interactionLambda.computeEnergy())
Example #4
0
    def setUp(self):
        # Initialize the espressopp system
        box = (10, 10, 10)
        system = espressopp.System()
        self.system = system
        system.kb = 1.0
        system.rng = espressopp.esutil.RNG()
        system.bc = espressopp.bc.OrthorhombicBC(system.rng, box)
        system.skin = 0.3

        nodeGrid = espressopp.tools.decomp.nodeGrid(MPI.COMM_WORLD.size)
        cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, 2.5,
                                                    system.skin)
        system.storage = espressopp.storage.DomainDecomposition(
            system, nodeGrid, cellGrid)

        # Adding ten nodes
        self.N = 8
        particle_list = []
        for pid in range(1, self.N + 1):
            pos = system.bc.getRandomPos()
            particle_list.append((pid, pos, 1 if pid < 5 else 2))
        system.storage.addParticles(particle_list, 'id', 'pos', 'res_id')
        system.storage.decompose()
        self.integrator = espressopp.integrator.VelocityVerlet(system)
        self.integrator.dt = 0.0025

        self.fpl1 = espressopp.FixedPairList(system.storage)
        self.fpl1.addBonds([(1, 2), (2, 3), (2, 4)])
        self.fpl2 = espressopp.FixedPairList(system.storage)
        self.fpl2.addBonds([(5, 6), (6, 7), (6, 8)])
        self.fpl3 = espressopp.FixedPairList(system.storage)

        self.ftl = espressopp.FixedTripleList(system.storage)
        self.ftl.addTriples([(1, 2, 3), (1, 2, 4), (5, 6, 7), (5, 6, 8)])

        self.fql = espressopp.FixedQuadrupleList(system.storage)
        self.fql2 = espressopp.FixedQuadrupleList(system.storage)

        topology_manager = espressopp.integrator.TopologyManager(system)
        self.topology_manager = topology_manager
        topology_manager.observe_tuple(self.fpl1)
        topology_manager.observe_tuple(self.fpl2)
        topology_manager.observe_tuple(self.fpl3)
        topology_manager.register_triplet(self.ftl, 0)
        topology_manager.register_quadruplet(self.fql, 0)
        topology_manager.register_quadruplet(self.fql2, 0, 0, 0, 1)
        topology_manager.register_tuple(self.fpl3, 0, 0)
        topology_manager.initialize_topology()
        self.integrator.addExtension(topology_manager)
Example #5
0
    def setUp(self):
        super(TestFixedTripleListTypesTabulated, self).setUp()
        # Test the energy computation. Distance between particles 1.0
        particle_list = [(1, 1, espressopp.Real3D(1.0, 1.0, 2.0)),
                         (2, 2, espressopp.Real3D(0.0, 0.0, 2.0)),
                         (3, 1, espressopp.Real3D(1.0, 0.0, 2.0)),
                         (4, 3, espressopp.Real3D(1.0, 0.0, 2.0)),
                         (5, 3, espressopp.Real3D(1.0, 1.0, 2.0))]
        self.system.storage.addParticles(particle_list, *self.part_prop)
        self.system.storage.decompose()

        self.ftl1 = espressopp.FixedTripleList(self.system.storage)
        self.ftl1.addTriples([(1, 2, 3), (4, 2, 5)])
        self.interaction = espressopp.interaction.FixedTripleListTypesTabulatedAngular(
            self.system, self.ftl1)
    def test_angular_harmonic_lambda(self):
        ftl_lambda = espressopp.FixedTripleListLambda(self.system.storage)
        ftl_lambda.addTriples([(1, 2, 3)])
        ftl = espressopp.FixedTripleList(self.system.storage)
        ftl.addTriples([(1, 2, 3)])
        harmonic = espressopp.interaction.AngularHarmonic()
        interactionLambda = espressopp.interaction.FixedTripleListLambdaAngularHarmonic(
            self.system, ftl_lambda, harmonic)
        interaction = espressopp.interaction.FixedTripleListAngularHarmonic(
            self.system, ftl, harmonic)

        self.fixed_dynamic_resolution.register_triple_list(ftl_lambda, -0.5)
        self.integrator.run(1)
        self.assertAlmostEqual(0.5 * interaction.computeEnergy(),
                               interactionLambda.computeEnergy())
Example #7
0
    def test_angular_harmonic_types_lambda(self):
        ftl_lambda = espressopp.FixedTripleListLambda(self.system.storage)
        ftl_lambda.addTriples([(1, 2, 3)])
        ftl = espressopp.FixedTripleList(self.system.storage)
        ftl.addTriples([(1, 2, 3)])
        harmonic = espressopp.interaction.AngularHarmonic()
        interactionLambda = espressopp.interaction.FixedTripleListTypesLambdaAngularHarmonic(
            self.system, ftl_lambda)
        interactionLambda.setPotential(0, 0, 1, harmonic)
        interaction = espressopp.interaction.FixedTripleListTypesAngularHarmonic(
            self.system, ftl)
        interaction.setPotential(0, 0, 1, harmonic)

        ftl_lambda.setAllLambda(0.5)
        self.assertAlmostEqual(0.5 * interaction.computeEnergy(),
                               interactionLambda.computeEnergy())
Example #8
0
def setAngleInteractions(system, input_conf, ftpl):
    ret_list = {}
    angletypeparams = input_conf.angletypeparams
    angles = input_conf.angletypes

    for (aid, cross_angles), anglelist in angles.iteritems():
        if ftpl:
            ftl = espressopp.FixedTripleListAdress(system.storage, ftpl)
        else:
            ftl = espressopp.FixedTripleList(system.storage)

        ftl.addTriples(anglelist)
        angleinteraction = angletypeparams[aid].createEspressoInteraction(system, ftl)
        if angleinteraction:
            system.addInteraction(angleinteraction, 'angle_{}{}'.format(
                aid, '_cross' if cross_angles else ''))
            ret_list.update({(aid, cross_angles): angleinteraction})
    return ret_list
Example #9
0
    def setUp(self):
        self.h5md_file = 'topo_output.h5'
        remove_file(self.h5md_file)
        self.system, self.integrator = espressopp.standard_system.Default(
            (10., 10., 10.), dt=0.1)

        self.particles = [(1, espressopp.Real3D(1, 2, 3), 1),
                          (2, espressopp.Real3D(2, 3, 4), 2),
                          (3, espressopp.Real3D(3, 4, 5), 3),
                          (4, espressopp.Real3D(4, 5, 6), 4)]

        self.system.storage.addParticles(self.particles, 'id', 'pos', 'type')

        self.fpl = espressopp.FixedPairList(self.system.storage)
        self.fpl.addBonds([(1, 2), (2, 3)])

        self.ftl = espressopp.FixedTripleList(self.system.storage)
        self.ftl.addTriples([(1, 2, 3)])

        self.fql = espressopp.FixedQuadrupleList(self.system.storage)
        self.fql.addQuadruples([(1, 2, 3, 4)])

        self.dump_h5md = espressopp.io.DumpH5MD(self.system,
                                                self.integrator,
                                                self.h5md_file,
                                                store_species=True,
                                                store_velocity=True,
                                                store_state=True)

        self.dump_topology = espressopp.io.DumpTopology(
            self.system, self.integrator, self.dump_h5md)
        self.dump_topology.observe_tuple(self.fpl, 'bonds_0')
        self.dump_topology.observe_triple(self.ftl, 'angles_0')
        self.dump_topology.observe_quadruple(self.fql, 'dihs_0')
        self.dump_topology.dump()
        ext_dump = espressopp.integrator.ExtAnalyze(self.dump_topology, 1)
        self.integrator.addExtension(ext_dump)
Example #10
0
                                            sigma=1.0,
                                            cutoff=rc,
                                            shift=0)
interLJ = espressopp.interaction.VerletListLennardJones(vl)
interLJ.setPotential(type1=0, type2=0, potential=potLJ)
system.addInteraction(interLJ)

# FENE bonds
fpl = espressopp.FixedPairList(system.storage)
fpl.addBonds(bonds)
potFENE = espressopp.interaction.FENE(K=30.0, r0=0.0, rMax=1.5)
interFENE = espressopp.interaction.FixedPairListFENE(system, fpl, potFENE)
system.addInteraction(interFENE)

# Cosine with FixedTriple list
ftl = espressopp.FixedTripleList(system.storage)
ftl.addTriples(angles)
potCosine = espressopp.interaction.Cosine(K=1.5, theta0=3.1415926)
interCosine = espressopp.interaction.FixedTripleListCosine(
    system, ftl, potCosine)
system.addInteraction(interCosine)

# print simulation parameters
print ''
print 'number of particles = ', num_particles
print 'density             = ', density
print 'rc                  = ', rc
print 'dt                  = ', integrator.dt
print 'skin                = ', system.skin
print 'temperature         = ', temperature
print 'nsteps              = ', nsteps
Example #11
0
    def setUp(self):
        # set up system
        system = espressopp.System()
        system.rng = espressopp.esutil.RNG()
        system.bc = espressopp.bc.OrthorhombicBC(system.rng, size)
        system.skin = skin

        comm = MPI.COMM_WORLD

        nodeGrid = Int3D(1, 1, comm.size)
        cellGrid = Int3D(calcNumberCells(size[0], nodeGrid[0], cutoff),
                         calcNumberCells(size[1], nodeGrid[1], cutoff),
                         calcNumberCells(size[2], nodeGrid[2], cutoff))
        system.storage = espressopp.storage.DomainDecomposition(
            system, nodeGrid, cellGrid)

        pid = 0

        system.storage.addParticle(0, Real3D(0.15, 0.1, 0))
        system.storage.addParticle(1, Real3D(0.4, 0.1, 0))

        system.storage.decompose()

        # integrator
        integrator = espressopp.integrator.VelocityVerlet(system)
        integrator.dt = 0.001

        # now build Verlet List
        # ATTENTION: you must not add the skin explicitly here
        logging.getLogger("Interpolation").setLevel(logging.INFO)
        vl = espressopp.VerletList(system, cutoff=cutoff)

        scaling_cv = 1.5
        alpha = 0.1

        # ATTENTION: auto shift was enabled
        # bonds
        writeTabFile(tabBonds[0], k=100000, x0=0.26, N=500, low=0.01, high=0.6)
        writeTabFile(tabBonds[1], k=50000, x0=0.24, N=500, low=0.01, high=0.6)

        fpl = espressopp.FixedPairList(system.storage)
        fpl.addBonds([(0, 1)])
        potBond = espressopp.interaction.TabulatedSubEns()
        potBond.addInteraction(
            1, tabBonds[0],
            espressopp.RealND([0.262, 0., 0., scaling_cv * 0.424, 0., 0.]))
        potBond.addInteraction(1, tabBonds[1],
                               espressopp.RealND([0., 0., 0., 0., 0., 0.]))
        potBond.alpha_set(alpha)
        cv_bl = espressopp.FixedPairList(system.storage)
        cv_bl.addBonds([])
        potBond.colVarBondList = cv_bl
        cv_al = espressopp.FixedTripleList(system.storage)
        cv_al.addTriples([])
        potBond.colVarAngleList = cv_al

        # Renormalize the CVs
        potBond.colVarSd_set(0, 0.0119)

        # Target probabilities
        potBond.targetProb_set(0, tgt_probs[0])
        potBond.targetProb_set(1, tgt_probs[1])

        interBond = espressopp.interaction.FixedPairListTabulatedSubEns(
            system, fpl, potBond)
        system.addInteraction(interBond)

        temp = espressopp.analysis.Temperature(system)

        temperature = temp.compute()
        Ek = 0.5 * temperature * (2 * numParticles)
        Ep = interBond.computeEnergy()

        # langevin thermostat
        langevin = espressopp.integrator.LangevinThermostat(system)
        integrator.addExtension(langevin)
        langevin.gamma = 1.0
        langevin.temperature = 2.479  # in kJ/mol

        # sock = espressopp.tools.vmd.connect(system)

        configurations = espressopp.analysis.Configurations(system)
        self.configuration = configurations
        self.system = system
        self.temp = temp
        self.integrator = integrator
        self.interBond = interBond
        self.potBond = potBond
Example #12
0
def applyBoreschRestraints(system, restraintAtoms, restraintK, restraintR0):

    restraintinteraction = {}

    restraintBond = espressopp.FixedPairList(system.storage)
    restraintBond.addBonds([(restraintAtoms['a'], restraintAtoms['A'])])
    potint = espressopp.interaction.FixedPairListHarmonic(
        system,
        restraintBond,
        potential=espressopp.interaction.Harmonic(K=0.5 * restraintK['aA'],
                                                  r0=restraintR0['aA'],
                                                  cutoff=5.0,
                                                  shift=0.0))
    system.addInteraction(potint)
    restraintinteraction.update({0: potint})

    restraintAngle = espressopp.FixedTripleList(system.storage)
    restraintAngle.addTriples([(restraintAtoms['a'], restraintAtoms['A'],
                                restraintAtoms['B'])])
    potint = espressopp.interaction.FixedTripleListAngularHarmonic(
        system,
        restraintAngle,
        potential=espressopp.interaction.AngularHarmonic(
            K=0.5 * restraintK['aAB'],
            theta0=restraintR0['aAB'] * math.pi / 180.0))
    system.addInteraction(potint)
    restraintinteraction.update({1: potint})

    restraintAngle = espressopp.FixedTripleList(system.storage)
    restraintAngle.addTriples([(restraintAtoms['b'], restraintAtoms['a'],
                                restraintAtoms['A'])])
    potint = espressopp.interaction.FixedTripleListAngularHarmonic(
        system,
        restraintAngle,
        potential=espressopp.interaction.AngularHarmonic(
            K=0.5 * restraintK['baA'],
            theta0=restraintR0['baA'] * math.pi / 180.0))
    system.addInteraction(potint)
    restraintinteraction.update({2: potint})

    restraintDih = espressopp.FixedQuadrupleList(system.storage)
    restraintDih.addQuadruples([(restraintAtoms['c'], restraintAtoms['b'],
                                 restraintAtoms['a'], restraintAtoms['A'])])
    potint = espressopp.interaction.FixedQuadrupleListDihedralHarmonic(
        system,
        restraintDih,
        potential=espressopp.interaction.DihedralHarmonic(
            K=restraintK['cbaA'], phi0=restraintR0['cbaA'] * math.pi / 180.0))
    system.addInteraction(potint)
    restraintinteraction.update({3: potint})

    restraintDih = espressopp.FixedQuadrupleList(system.storage)
    restraintDih.addQuadruples([(restraintAtoms['b'], restraintAtoms['a'],
                                 restraintAtoms['A'], restraintAtoms['B'])])
    potint = espressopp.interaction.FixedQuadrupleListDihedralHarmonic(
        system,
        restraintDih,
        potential=espressopp.interaction.DihedralHarmonic(
            K=restraintK['baAB'], phi0=restraintR0['baAB'] * math.pi / 180.0))
    system.addInteraction(potint)
    restraintinteraction.update({4: potint})

    restraintDih = espressopp.FixedQuadrupleList(system.storage)
    restraintDih.addQuadruples([(restraintAtoms['a'], restraintAtoms['A'],
                                 restraintAtoms['B'], restraintAtoms['C'])])
    potint = espressopp.interaction.FixedQuadrupleListDihedralHarmonic(
        system,
        restraintDih,
        potential=espressopp.interaction.DihedralHarmonic(
            K=restraintK['aABC'], phi0=restraintR0['aABC'] * math.pi / 180.0))
    system.addInteraction(potint)
    restraintinteraction.update({5: potint})

    return restraintinteraction
Example #13
0
                                        (float(parameters[7 - i_diff]) + 2.*L)%L,
                                        (float(parameters[8 - i_diff]) + 2.*L)%L)
      print i*monomers_per_chain + j, " ", res_positions
      radius = float(parameters[10 - i_diff])
      part = [res_positions, radius]
      cg_chain.append(part)
      j +=1

# Init fine-grained polymer configuration
N_blob = N_blob/2
monomers_per_chain *= 2

props    = ['id', 'type', 'mass', 'pos', 'v', 'radius', 'vradius']

bondlist  = espressopp.FixedPairList(system.storage)
anglelist = espressopp.FixedTripleList(system.storage)
tuplelist = espressopp.FixedLocalTupleList(system.storage)
pid      = 1
type     = 0
mass     = 1.0*N_blob

integrator.dt  = timestep*(mass*B_cg**2/temperature)**0.5 #0.005*sqrt(Nb*m*l^2/kbT)=unit_time/200
#integrator.dt  = timestep*(mass/temperature)**0.5 #0.005*sqrt(Nb*m*l^2/kbT)=unit_time/200/B_cg

chain = []
for i in range(num_chains):
  startpos = system.bc.getRandomPos()
  positions, bonds, angles = espressopp.tools.topology.polymerRW(pid, startpos, monomers_per_chain, bondlen, True)
  for j in range(monomers_per_chain/2):
    id = i*(monomers_per_chain/2) + j
    vector = []
Example #14
0
def init_polymer_melt_simulation(use_replicate_parallel):

    start_time = time.process_time()

    bonds, angles, x, y, z, Lx, Ly, Lz = espressopp.tools.lammps.read('polymer_melt.lammps')

    if use_replicate_parallel:
        # rp stores bonds, angles, and positions
        rp = espressopp.tools.ReplicateParallel()
        num_particles, Lx, Ly, Lz = rp.replicate(bonds, angles, x, y, z, Lx, Ly, Lz, *repl)
    else:
        bonds, angles, x, y, z, Lx, Ly, Lz = espressopp.tools.replicate(bonds, angles, x, y, z, Lx, Ly, Lz, *repl)
        num_particles = len(x)

    density = num_particles / (Lx * Ly * Lz)
    box = (Lx, Ly, Lz)
    system, integrator = espressopp.standard_system.Default(box=box, rc=rc, skin=skin, dt=timestep, temperature=temperature)

    if use_replicate_parallel:
        props = ['type', 'mass']
        num_particles_seed = len(x)
        seed_particles = []
        for i in range(num_particles_seed):
            part = [0, 1.0]
            seed_particles.append(part)
        # rp workers add replicated particles in parallel
        rp.addParticles(system.storage, 1, seed_particles, *props)
    else:
        # add particles to the system and then decompose
        # do this in chunks of 1000 particles to speed it up
        props = ['id', 'type', 'mass', 'pos']
        new_particles = []
        for i in range(num_particles):
            part = [i + 1, 0, 1.0, espressopp.Real3D(x[i], y[i], z[i])]
            new_particles.append(part)
            if i % 1000 == 0:
                system.storage.addParticles(new_particles, *props)
                system.storage.decompose()
                new_particles = []
        system.storage.addParticles(new_particles, *props)

    system.storage.decompose()

    # Lennard-Jones with Verlet list
    vl      = espressopp.VerletList(system, cutoff = rc)
    potLJ   = espressopp.interaction.LennardJones(epsilon=1.0, sigma=1.0, cutoff=rc, shift=0)
    interLJ = espressopp.interaction.VerletListLennardJones(vl)
    interLJ.setPotential(type1=0, type2=0, potential=potLJ)
    system.addInteraction(interLJ)

    # FENE bonds
    fpl = espressopp.FixedPairList(system.storage)
    if use_replicate_parallel:
        # rp workers add replicated bonds in parallel
        rp.addBonds(fpl)
    else:
        fpl.addBonds(bonds)
    potFENE = espressopp.interaction.FENE(K=30.0, r0=0.0, rMax=1.5)
    interFENE = espressopp.interaction.FixedPairListFENE(system, fpl, potFENE)
    system.addInteraction(interFENE)

    # Cosine with FixedTriple list
    ftl = espressopp.FixedTripleList(system.storage)
    if use_replicate_parallel:
        # rp workers add replicated triples in parallel
        rp.addTriples(ftl)
    else:
        ftl.addTriples(angles)
    potCosine = espressopp.interaction.Cosine(K=1.5, theta0=3.1415926)
    interCosine = espressopp.interaction.FixedTripleListCosine(system, ftl, potCosine)
    system.addInteraction(interCosine)

    end_time = time.process_time()

    # get positions, bonds and angles
    configurations = espressopp.analysis.Configurations(system, pos=True, vel=False, force=False)
    configurations.gather()
    pos = [configurations[0][i] for i in range(num_particles)]
    bonds = np.array(fpl.getBonds())
    angles = np.array(ftl.getTriples())

    return end_time - start_time, pos, bonds, angles
Example #15
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)
Example #16
0
 def test_set_fixedtriplelist(self):
     ftl = espressopp.FixedTripleList(self.system.storage)
     ftl.addTriples([(1, 1, 1)])
     self.interaction.setFixedTripleList(ftl)
     ret_ftl = self.interaction.getFixedTripleList()
     self.assertEqual(ret_ftl.getTriples(), [[(1, 1, 1)]])