Skip to content

Instantly share code, notes, and snippets.

@jkrajniak
Last active August 10, 2016 19:38
Show Gist options
  • Save jkrajniak/b63ee696ec6b443d115fb553998f1fc8 to your computer and use it in GitHub Desktop.
Save jkrajniak/b63ee696ec6b443d115fb553998f1fc8 to your computer and use it in GitHub Desktop.
Espresso/pp minimize energy
#!/usr/bin/env python
import sys
import time
import espressomd
system = espressomd.System()
#gamma = 0.001, ftol=1.0, displa 0.001
system.minimize_energy.init(
f_max=1.0,
gamma=0.001,
max_steps=2000,
max_displacement=0.001)
system.skin = 0.3
system.time_step = 0.001
system.periodicity = [1, 1, 1]
system.box_l = (10.0, 10.0, 10.0)
system.non_bonded_inter[0, 0].lennard_jones.set_params(
epsilon=1.0, sigma=1.0, cutoff=3.0, shift='auto')
system.part.add(id=1, pos=(2.0, 2.0, 2.0), mass=1.0, type=0)
system.part.add(id=2, pos=(2.1, 2.0, 2.0), mass=1.0, type=0)
energies0 = system.analysis.energy()
print 'before', energies0['total'], '1', system.part[1].pos, '2', system.part[2].pos
system.minimize_energy.minimize()
energies1 = system.analysis.energy()
print 'after', energies1['total'], '1', system.part[1].pos, '2', system.part[2].pos
# Set position and compute energy
# ESPP: 0.00547944174424
system.part[1].pos = (1.0, 2.0, 2.0)
system.part[2].pos = (2.0, 2.0, 2.0)
print 'after', system.analysis.energy()['total'], '1', system.part[1].pos, '2', system.part[2].pos
print 'espp ', 0.00547944174424
#!/usr/bin/env python
import sys
import time
import espressopp
import mpi4py.MPI as MPI
system = espressopp.System()
system.bc = espressopp.bc.OrthorhombicBC(system.rng, (10, 10, 10))
system.skin = 0.3
system.comm = MPI.COMM_WORLD
system.storage = espressopp.storage.DomainDecomposition(system)
system = system
particle_list = [
(1, espressopp.Real3D(2.0, 2.0, 2.0), 1.0),
(2, espressopp.Real3D(2.1, 2.0, 2.0), 1.0),
]
system.storage.addParticles(particle_list, 'id', 'pos', 'mass')
system.storage.decompose()
minimize_energy = espressopp.integrator.MinimizeEnergy(
system, gamma=0.001, ftol=1.0, max_displacement=0.001)
vl = espressopp.VerletList(system, cutoff=3.0)
lj = espressopp.interaction.LennardJones(sigma=1.0, epsilon=1.0, cutoff=3.0, shift='auto')
interaction = espressopp.interaction.VerletListLennardJones(vl)
interaction.setPotential(type1=0, type2=0, potential=lj)
system.addInteraction(interaction)
energy_before = interaction.computeEnergy()
print 'before', energy_before, system.storage.getParticle(1).pos, system.storage.getParticle(2).pos
minimize_energy.run(2000)
print 'after', interaction.computeEnergy(), system.storage.getParticle(1).pos, system.storage.getParticle(2).pos
system.storage.modifyParticle(1, 'pos', espressopp.Real3D(1.0, 2.0, 2.0))
system.storage.modifyParticle(2, 'pos', espressopp.Real3D(2.0, 2.0, 2.0))
print 'after', interaction.computeEnergy(), system.storage.getParticle(1).pos, system.storage.getParticle(2).pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment