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)
def test_tab_dih(self): # integrator integrator = espressopp.integrator.VelocityVerlet(self.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(self.system, cutoff = cutoff) # bonds writeTabFile(tabBond, k=400000, x0=0.4, N=500, low=0.01, high=0.80) fpl = espressopp.FixedPairList(self.system.storage) fpl.addBonds([(0,1),(1,2),(2,3)]) potBond = espressopp.interaction.Tabulated(itype=spline, filename=tabBond) interBond = espressopp.interaction.FixedPairListTabulated(self.system, fpl, potBond) self.system.addInteraction(interBond) # dihedral spring = 10 x_rest = 0.0 writeTabFile(tabDih, k=spring, x0=x_rest, N=500, low=-np.pi, high=np.pi) fql = espressopp.FixedQuadrupleList(self.system.storage) fql.addQuadruples([(0,1,2,3)]) potDihed1 = espressopp.interaction.TabulatedDihedral(itype=spline, filename=tabDih) interDihed1 = espressopp.interaction.FixedQuadrupleListTabulatedDihedral(self.system, fql, potDihed1) potDihed2 = espressopp.interaction.DihedralHarmonic(spring, x_rest) interDihed2 = espressopp.interaction.FixedQuadrupleListDihedralHarmonic(self.system, fql, potDihed2) self.system.addInteraction(interDihed1) temp = espressopp.analysis.Temperature(self.system) temperature = temp.compute() Ek = 0.5 * temperature * (3 * numParticles) Ep = interDihed1.computeEnergy() # langevin thermostat langevin = espressopp.integrator.LangevinThermostat(self.system) integrator.addExtension(langevin) langevin.gamma = 1.0 langevin.temperature = 2.479 # in kJ/mol print("Running at temperature T = {:.3f} kJ/mol/k_B".format(langevin.temperature)) start_time = time.process_time() print(" ***") print("{:8s} {:8s} {:8s}".format("Step","E_tab","E_harm")) for k in range(nsnapshots): Ed1, Ed2 = interDihed1.computeEnergy(), interDihed2.computeEnergy() if k % 10 == 0: self.assertAlmostEqual(Ed1, Ed2, places=2) print('{:8d} {:8f} {:8f}'.format(((k+10)*nsteps),Ed1, Ed2)) integrator.run(nsteps)
def test_dihedral_harmonic(self): ftl_lambda = espressopp.FixedQuadrupleListLambda(self.system.storage) ftl_lambda.addQuadruples([(1, 2, 3, 4)]) ftl = espressopp.FixedQuadrupleList(self.system.storage) ftl.addQuadruples([(1, 2, 3, 4)]) interactionLambda = espressopp.interaction.FixedQuadrupleListLambdaDihedralRB( self.system, ftl_lambda, self.potential) interaction = espressopp.interaction.FixedQuadrupleListDihedralRB( self.system, ftl, self.potential) self.assertAlmostEqual(interaction.computeEnergy(), interactionLambda.computeEnergy())
def test_dihedral_harmonic_lambda(self): ftl_lambda = espressopp.FixedQuadrupleListLambda(self.system.storage) ftl_lambda.addQuadruples([(1, 2, 3, 4), (2, 1, 3, 4)]) ftl = espressopp.FixedQuadrupleList(self.system.storage) ftl.addQuadruples([(1, 2, 3, 4), (2, 1, 3, 4)]) interactionLambda = espressopp.interaction.FixedQuadrupleListLambdaDihedralRB( self.system, ftl_lambda, self.potential) interaction = espressopp.interaction.FixedQuadrupleListDihedralRB( self.system, ftl, self.potential) self.fixed_dynamic_resolution.register_quadruple_list(ftl_lambda, -0.5) self.integrator.run(1) self.assertAlmostEqual(0.5 * interaction.computeEnergy(), interactionLambda.computeEnergy())
def setUp(self): super(TestFixedQuadrupleListTypesTabulated, self).setUp() # Test the energy computation. Distance between particles 1.0 particle_list = [ (1, 1, espressopp.Real3D(0.0, 0.0, 0.0)), (2, 1, espressopp.Real3D(2.0, 0.0, 0.0)), (3, 1, espressopp.Real3D(2.0, 0.0, 2.0)), (4, 1, espressopp.Real3D(2.0, 2.0, 2.0)), ] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() self.fql1 = espressopp.FixedQuadrupleList(self.system.storage) self.fql1.addQuadruples([(1, 2, 3, 4)]) self.interaction = espressopp.interaction.FixedQuadrupleListTypesTabulatedDihedral(self.system, self.fql1)
def test_dihedral_harmonic_types_lambda(self): ftl_lambda = espressopp.FixedQuadrupleListLambda(self.system.storage) ftl_lambda.addQuadruples([(1, 2, 3, 4)]) ftl = espressopp.FixedQuadrupleList(self.system.storage) ftl.addQuadruples([(1, 2, 3, 4)]) interactionLambda = espressopp.interaction.FixedQuadrupleListTypesLambdaDihedralRB( self.system, ftl_lambda) interactionLambda.setPotential(0, 0, 1, 1, self.potential) interaction = espressopp.interaction.FixedQuadrupleListTypesDihedralRB( self.system, ftl) interaction.setPotential(0, 0, 1, 1, self.potential) ftl_lambda.setAllLambda(0.5) self.assertEqual(ftl_lambda.getLambda(1, 2, 3, 4), [0.5]) self.assertAlmostEqual(0.5 * interaction.computeEnergy(), interactionLambda.computeEnergy())
def setDihedralInteractions(system, input_conf, ftpl): ret_list = {} dihedrals = input_conf.dihedraltypes dihedraltypeparams = input_conf.dihedraltypeparams for (did, cross_dih), dihedrallist in dihedrals.iteritems(): if ftpl: fql = espressopp.FixedQuadrupleListAdress(system.storage, ftpl) else: fql = espressopp.FixedQuadrupleList(system.storage) fql.addQuadruples(dihedrallist) dihedralinteraction = dihedraltypeparams[did].createEspressoInteraction(system, fql) if dihedralinteraction: system.addInteraction(dihedralinteraction, 'dihedral_{}{}'.format( did, '_cross' if cross_dih else '')) ret_list.update({(did, cross_dih): dihedralinteraction}) return ret_list
def test_dihedral_harmonic_lambda_selective(self): ftl_lambda = espressopp.FixedQuadrupleListLambda(self.system.storage) ftl_lambda.addQuadruples([(1, 2, 3, 4), (2, 1, 3, 4)]) ftl = espressopp.FixedQuadrupleList(self.system.storage) ftl.addQuadruples([(1, 2, 3, 4)]) interactionLambda = espressopp.interaction.FixedQuadrupleListLambdaDihedralRB( self.system, ftl_lambda, self.potential) interaction = espressopp.interaction.FixedQuadrupleListDihedralRB( self.system, ftl, self.potential) self.assertEqual(ftl_lambda.getLambda(1, 2, 3, 4), [1.0]) self.assertEqual(ftl_lambda.getLambda(2, 1, 3, 4), [1.0]) ftl_lambda.setLambda(1, 2, 3, 4, 1.0) ftl_lambda.setLambda( 2, 1, 3, 4, 0.0) # Switch completely this tuple by setting lambda=0.0 self.assertAlmostEqual(interaction.computeEnergy(), interactionLambda.computeEnergy()) self.assertEqual(ftl_lambda.getLambda(1, 2, 3, 4), [1.0]) self.assertEqual(ftl_lambda.getLambda(2, 1, 3, 4), [0.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)
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
def test_phi0(self): #create system with three torsions, and for each one set a potential with a different phi0 values, to check that the interaction potential works for all combinations of positive and negative phi and phi0 phi0 = [10.0, -170.0, 170.0] particle_list = [ #add particles with initial torsion angle +90 (1, 0, espressopp.Real3D(2.0, 3.0, 3.0), 1.0), (2, 0, espressopp.Real3D(2.0, 2.0, 3.0), 1.0), (3, 0, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (4, 0, espressopp.Real3D(3.0, 2.0, 2.0), 1.0), #add particles with initial torsion angle 160 (5, 0, espressopp.Real3D(2.0, 3.0, 3.0), 1.0), (6, 0, espressopp.Real3D(2.0, 2.0, 3.0), 1.0), (7, 0, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (8, 0, espressopp.Real3D(2.4, 0.8, 2.0), 1.0), #add particles with initial torsion angle -161 (9, 0, espressopp.Real3D(2.0, 3.0, 3.0), 1.0), (10, 0, espressopp.Real3D(2.0, 2.0, 3.0), 1.0), (11, 0, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (12, 0, espressopp.Real3D(1.6, 0.8, 2.0), 1.0), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'pos', 'mass') self.system.storage.decompose() quadrupleslist = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] torsiontuples = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)] bondtuples = [(1, 2), (2, 3), (3, 4), (5, 6), (6, 7), (7, 8), (9, 10), (10, 11), (11, 12)] #add torsions interactions = [] for i in range(3): fql = espressopp.FixedQuadrupleList(self.system.storage) fql.addQuadruples([torsiontuples[i]]) interaction = espressopp.interaction.FixedQuadrupleListDihedralHarmonic( self.system, fql, potential=espressopp.interaction.DihedralHarmonic( K=1.0, phi0=phi0[i] * math.pi / 180.0)) self.system.addInteraction(interaction) interactions.append(interaction) #add bonds so that atoms in the torsions don't drift too far apart fpl = espressopp.FixedPairList(self.system.storage) fpl.addBonds(bondtuples) interaction = espressopp.interaction.FixedPairListHarmonic( self.system, fpl, potential=espressopp.interaction.Harmonic(K=1.0, r0=1.0)) self.system.addInteraction(interaction) integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.run(50) self.assertAlmostEqual(interactions[0].computeEnergy(), 0.747885, places=5) self.assertAlmostEqual(interactions[1].computeEnergy(), 0.099570, places=5) self.assertAlmostEqual(interactions[2].computeEnergy(), 0.099570, places=5) self.assertAlmostEqual(calc_dihedral(self, quadrupleslist[0]), 1.397549, places=5) self.assertAlmostEqual(calc_dihedral(self, quadrupleslist[1]), 2.869874, places=5) self.assertAlmostEqual(calc_dihedral(self, quadrupleslist[2]), -2.869874, places=5)
def test_set_fixedquadruplelist(self): fql = espressopp.FixedQuadrupleList(self.system.storage) fql.addQuadruples([(1, 1, 1, 1)]) self.interaction.setFixedQuadrupleList(fql) ret_fql = self.interaction.getFixedQuadrupleList() self.assertEqual(ret_fql.getQuadruples(), [[(1, 1, 1, 1)]])