ESPResSo Summer School 2013 October 7 to October 11, University of Stuttgart

Simulating Soft Matter with ESPResSo, ESPResSo++ and VOTCA

Max Planck Institute http://www.espresso-pp.de for Polymer Research ESPResSo++ Key Features

• ESPResSo++ is an open-source simulation package designed to perform and monte carlo simulations of condensed matter systems using traditional and state-of-the-art techniques. • Flexibility due to Python/C++ integration Analysis Visualization • Extensibility due to object oriented design • Easy script-guided creation of complex NumPy SciPy PyMol VMD topologies • Quick incorporation of new interactions and analysis methods Python scripting • Use of standard short- and long range language interactions: e.G. Lennard-Jones, Stillinger- Weber, FENE, OPLS, Dihedrals, Ewald Advanced C++ Kernel Coulomb, etc. • Parallelization • Efficient implementation of advanced • Time-critical algorithms: e.G. (H-)AdResS, Parallel algorithms Tempering, dynamic bonds, etc. • Data storage • On-the-fly analysis and visualization • Extensible modular • Applicable to large systems and large numbers design of CPUs due to efficient parallelisation Outline of the talk

• Simulating a dense polymer melt (general workflow) • Some things to know about python • Typical ESPResSo++ python script and ESPResSo++ modules hierarchy • System setup and basic classes - Some information about PMI in between • Inside ESPReSo++ an overview of the C++ class structure • Integrator, Interactions, Storage

Outline of the afternoon tutorial session • Installation of ESPResSo++ • Basic System Setup • Simple Lennard Jones System • Advanced Lennard Jones System with graphical output • Polymer Melt

Example: simulating a dense polymer melt

System setup

Create random polymer chains

Warmup the system

Equilibrate the system

Snapshot of an equilibrated dense ring polymer melt, Output equilibrated number of chains Nc=200, chain length lc=200 particles, density ρ=0.85 [N/V3] configuration

You will have time in the afternoon tutorial session to work with this example in more detail. Example: simulating a dense polymer melt

System setup

Create random polymer chains

Warmup the system

Equilibrate the system

Snapshot of an equilibrated dense ring polymer melt, Output equilibrated number of chains Nc=200, chain length lc=200 particles, density ρ=0.85 [N/V3] configuration

The following slides will show how basic modules of ESPResSo++ can be used to setup a system for the simulation of a polymer melt. Some (very few) things to know about Python: • Python is an interpreted language and does not have to be compiled • Python has advanced object oriented structures • Python can be used interactively

There is one syntactic specialty in python (and I don't know any other language that has this) : begin and end of a block is not marked by any keyword or brackets but only by indentation. ( Therefore it is very important to be disciplined when indenting the lines ! ) examples: for i in range(100): s += i print s, i or if (sum > 100): print 'sum = ', sum sum = 0

A typical ESPResSo++ python script consists of the following elements:

• System setup (define box, interactions, parameters, ...)

• Read in particle and topology information from a file (e.g. pdb, xyz, GROMACS or LAMMPS) or setup a new random configuration

• Integrate Newtons equations of motion

• Analysis, trajectory files, visualization and many other things can be done during integration

• Print final results

There is only one python script needed to reflect the workflow of a complete project ! Python import espresso

OPLS • Typically ESPResSo++ python

scripts start with the line: Exten- sions BC esutil. RNG • All ESPResSo++ modules and compute classes will then be available Systemt emperature and are prefixed with

Verlet List

RNG Ortho- rhombicBC Python import espresso

The main ESPResSo++ modules are

(basic classes, e.g. Particle, data types like Real3D or Tensor and the System class, ...) (e.g. Temperature, PressureTensor, g(r), ...) (boundary condition classes, e.g. OrthorhombicBC) (e.g. random number generators, ...) (e.g. VelocityVerlet, extensions like thermostats and barostats, ...) (e.g. LennardJones, FENE, OPLS, Tabulated, ...) (new file I/O classes, e.g. DumpXYZ, ...) (e.g. domain decomposition) (old file I/O classes, e.g. writepdb, interface to other programs like VMD, GROMACS, LAMMPS, ...)

• This hierarchy is also reflected by the directory structure of the src (espresso) directory-tree System setup and basic classes Python system = espresso.System()

RNG

The System class holds links to other classes that are necessary for most simulations: BC

• System Random number generators Storage • Boundary conditions • Storage Inter- • Interactions actions

• PMI takes care of the parallelisation on the python level • This will be explained in more detail on the next slide Some words about parallelisation and PMI:

distributes objects (transparently for the Python module PMI user) to parallel threads and invokes them

( Parallel Method Invokation ) controller (distributes objects to workers and keeps track of return values)

worker 1 worker 2 worker 3 worker 4

RNG RNG RNG RNG

BC BC BC BC

System System System CPU 1 System CPU 2 CPU 3 CPU 4 Stora Stora Stora Stora ge ge ge ge

Inter- Inter- Inter- Inter- actio actio actio actio ns ns ns ns

Workers communicate to each other via MPI on C++ or Python level Python system.rng = espresso.esutil.RNG()

esutil. • We create a random number RNG generator object and connect it RNG to the system. • (Remember: PMI will take care BC

of doing this on all the System workers.) Storage • Other objects, e.g. the Langevin thermostat extension can use Inter- the RNG of the system actions

• Always remember: PMI takes care of distributing the objects to the works • Usually this is totally transparent for the user Python system.storage = espresso.bc.OrthorhombicBC( box, ... )

esutil. • Next comes the boundary RNG condition object. RNG • This class takes care of Ortho- BC measuring distances rhombicBC

• It has information about the System size of the simulation box Storage • And it can create random coordinates within the Inter- simulation box actions • Therefore it also needs a RNG Python system.storage = espresso.storage.DomainDecomposition(*)

esutil. • The next important object that RNG we need to create is the RNG domain decomposition object Ortho- BC • It takes care of storing all the rhombicBC

particles in a multi CPU System Domain Storage environment decomposition • It also handles sending around particles between CPUs via Inter- mpi_recv and mpi_send (we actions use boost::mpi for that) • It informs other objects (like particle lists or bond lists) when this happens so that they can also update their data Python integrator = espresso.integrator.VelocityVerlet( system )

Velocity esutil. System RNG

Verlet RNG

Ortho- BC • Another important object rhombicBC

we need for our daily System Domain Integrator Storage simulations is the decomposition integrator • It integrates Newtons Exten- Inter- equations of motion with sions actions a Velocity-Verlet type scheme • It also send signals to the integrator extensions and allows them interfere in the scheme Python system.storage.addParticles( particleList, *particleProperties )

Velocity esutil. System RNG

Verlet RNG

Ortho- BC

rhombicBC System Domain particleList = Integrator Storage decomposition [ [1, 0, pos1, 1.0], [2, 0, pos2, 1.0], Exten- Inter- . sions actions . . [N, 0, posN, 1.0] ] • We can add some particles now Particle Particle Particle particleProperties = • Each particle is 1 2 ... N ['id', 'type', 'pos', 'mass'] stored on one CPU only Python system.addInteraction(interaction1)

Velocity esutil. System RNG

Verlet RNG

Ortho- BC rhombicBC

• The system also holds a list System Domain Integrator Storage to all the interactions of the decomposition simulation Exten- Inter- sions actions verletlist = espresso.VerletList(system, cutoff) Verlet LJ List LJpot = espresso.interaction.LennardJones (epsilon, sigma, cutoff, shift) • Interactions consist of two parts: the interaction1 = espresso.interaction. VerletListLennardJones(verletlist) actual potential (e.g. Lennard Jones) interaction1.setPotential and the type (nonbonded=Verlet*, (type1=0, type2=0, LJpot) bonded=Fixed*Lists) Python system.addInteraction(interaction2)

Velocity esutil. System RNG

Verlet RNG

Ortho- BC

• ESPResSo++ supports many rhombicBC System different kinds of Domain Integrator Storage interactions: 2-body bonded decomposition and non bonded, 3-body Exten- Inter- bonded and non bonded sions actions (angular), 4-body bonded

(dihedrals) Verlet LJ List

Pair FENE List

Python system.addInteraction(interaction3)

Velocity esutil. System RNG

Verlet RNG

Ortho- BC

rhombicBC System Domain • The cosine_squared is an Integrator Storage decomposition example of 3-body bonded potential Exten- Inter- • Stillinger Weber or Tersoff sions actions

are examples for 3-body Verlet LJ non bonded potentials that List

work with 3-body Verlet

Pair lists FENE List

Angle Cos2 List

Python integrator.addExtension(thermostat)

Velocity esutil. System RNG

Verlet RNG

Ortho- BC

• Things like rhombicBC System thermostats, barostats, Domain Integrator Storage external forces and decomposition many others are implemented as Exten- Inter- sions actions integrator extensions

• There will be a Langevin Verlet LJ Thermostat List detailed explanation of

this later in the talk Pair FENE List thermostat = espresso.integrator

.LangevinThermostat Angle Cos2 thermostat.gamma = 1.0 List thermostat.temperature = 1.0 Python integrator.addExtension(analysis)

Velocity esutil. System RNG

Verlet RNG

Ortho- BC • Even analysis routines can be rhombicBC

added as extensions. System Domain • This allows for efficient Integrator Storage decomposition calculation of running averages and error bars Exten- Inter- without leaving the C++ level sions actions

Langevin Verlet LJ Thermostat List

compute compute Pair Analysis FENE PressureTensor temperature List

Angle Cos2 List

• Finally integrate Newtons equation of motion - print some analysis information during integration • Write final configuration to PDB file

for nsteps in range(1000)

integrator.run(100)

print(espresso.analysis.Temperature.compute())

espresso.tools.pdbwrite( filename='data.pdb', system ) System actions Inter LJ

System

Storage Exten grator sions FENE Inte RNG BC

-

-

Langevin Particles Cos 2

Simplyfied summary Simplyfied

i i1.addExtension(langevin_thermostat) integrator.VelocityVerlet( = i1 s1.addInteraction(CosSq s1.addInteraction(FENE) s1.addInteraction(LJ) s1.storage.addParticles(*property_list, = s1.storage = s1.bc = s1.rng System() = s1 1.run(10000) storage.DomainDecomposition() ......

with thermostat with interactions

bc.OrthorhombicBC() esutil.RNG()

)

particle_list)

s1 )

Inside ESPResSo++

• Abstract classes • The integrator • How integrator extensions work • Interaction types • Potentials • Storage Abstract classes of ESPResSo++

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

Interaction BoundaryConditions Storage

VerletListInteraction OrthorhombicBC Domain < LennardJones > Decomposition

System Abstract classes of ESPResSo++

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

Interaction BoundaryConditions Storage

VerletListInteraction OrthorhombicBC Domain < LennardJones > Decomposition

System Integrator

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

Init 푓푖& 푡 &= 퐹푖 푡 & & BoundaryConditions Storage Interaction 푣푖& 푡 + ∆푡 2& &= 푣푖 푡 &+& ∆푡 2 &⋅&푓푖 푡 & 푟 & 푡 + ∆푡 & &= 푟 푡 &+&∆푡 &⋅&푣 푡 + ∆푡 2 푖 푖 푖 & VerletListInteraction OrthorhombicBC Domain & MD< LennardJones > Decomposition 푓푖& 푡 &= 퐹푖 푡 Loop & & 푣푖& 푡 + ∆푡 & &= 푣푖 푡 + ∆푡 2 &+& ∆푡 2 &⋅&푓푖 푡 &&&

System How integrator extensions work

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

signal

Init 푓푖& 푡 &= 퐹푖 푡 signal & Interaction BoundaryConditions Storage 푣푖& 푡 + ∆푡 2& &= 푣푖 푡 &+& ∆푡 2 &⋅&푓푖 푡 & 푟 & 푡 + ∆푡 & &= 푟 푡 &+&∆푡 &⋅&푣 푡 + ∆푡 2 푖 푖 푖 VerletListInteraction & OrthorhombicBC Domain signal MD< LennardJones > Decomposition 푓푖& 푡 &= 퐹푖 푡 Loop & signal

푣푖& 푡 + ∆푡 & &= 푣푖 푡 + ∆푡 2 &+& ∆푡 2 &⋅&푓푖 푡 &&&

signal System Extensions

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

signal

Init 푓푖& 푡 &= 퐹푖 푡 signal +&푳 푻, 휸, 풗 풕 , 휽 & 풊 Interaction BoundaryConditions Storage 푣푖& 푡 + ∆푡 2& &= 푣푖 푡 &+& ∆푡 2 &⋅&푓푖 푡 & 푟 & 푡 + ∆푡 & &= 푟 푡 &+&∆푡 &⋅&푣 푡 + ∆푡 2 푖 푖 푖 VerletListInteraction & OrthorhombicBC Domain signal MD< LennardJones > Decomposition 푓푖& 푡 &= 퐹푖 푡 Loop & signal +&푳′ 푻, 휸, 풗풊 풕 + ∆풕 ퟐ , 휽 푣푖& 푡 + ∆푡 & &= 푣푖 푡 + ∆푡 2 &+& ∆푡 2 &⋅&푓푖 푡 &&&

signal System Extensions

Extension FixPositions

signals signals

Integrator VelocityVerlet

signal

Init 푓푖& 푡 &= 퐹푖 푡 signal save positions & Interaction BoundaryConditions Storage 푣푖& 푡 + ∆푡 2& &= 푣푖 푡 &+& ∆푡 2 &⋅&푓푖 푡 & 푟 & 푡 + ∆푡 & &= 푟 푡 &+&∆푡 &⋅&푣 푡 + ∆푡 2 푖 푖 푖 VerletListInteraction & OrthorhombicBC Domain signal restore positions MD< LennardJones > Decomposition 푓푖& 푡 &= 퐹푖 푡 Loop & signal

푣푖& 푡 + ∆푡 & &= 푣푖 푡 + ∆푡 2 &+& ∆푡 2 &⋅&푓푖 푡 &&&

signal System Extensions

Extension ForceCapping

signals signals

Integrator VelocityVerlet

signal

Init 푓푖& 푡 &= 퐹푖 푡 signal & Interaction BoundaryConditions Storage 푣푖& 푡 + ∆푡 2& &= 푣푖 푡 &+& ∆푡 2 &⋅&푓푖 푡 & 푟 & 푡 + ∆푡 & &= 푟 푡 &+&∆푡 &⋅&푣 푡 + ∆푡 2 푖 푖 푖 VerletListInteraction & OrthorhombicBC Domain signal MD< LennardJones > Decomposition 푓푖& 푡 &= 퐹푖 푡 Loop & signal cap forces

푣푖& 푡 + ∆푡 & &= 푣푖 푡 + ∆푡 2 &+& ∆푡 2 &⋅&푓푖 푡 &&&

signal System Extensions

Extension LangevinThermo/Barostat

signals BerendsenThermo/Barostat signals

Integrator (T)VelocityVerletDPDThermostat

StochasticVelocityRescaling

Isokinetic Storage Interaction BoundaryConditions FixPositions

ExtForce / TDForce Domain VerletListInteraction OrthorhombicBC Decomposition ForceCapping < LennardJones > AdResS

Analysis

System File I/O Abstract classes

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

Interaction BoundaryConditions Storage

VerletListInteraction OrthorhombicBC Domain < LennardJones > Decomposition

System Interaction types

Extension LangevinThermostat

signals signals Different types of interaction: Integrator VelocityVerlet • 2-body (pair) • 3-body (angular) • 4-body (dihedral) • N-body (coulomb k-space) • non bonded (Verlet lists) Interaction BoundaryConditions Storage • bonded (bond lists)

VerletListInteraction OrthorhombicBC Domain < LennardJones > Decomposition

System Interaction types

2-body Extension3-body 4-body N-body LangevinThermostat

signals signals VerletList Integrator VelocityVerlet VerletListAdress

VerletListTriple Storage CellListAllPairs Interaction BoundaryConditions CellListAllParticlesDomain Decomposition

VerletListInteraction OrthorhombicBC FixedPairList < LennardJones > FixedTripleList

FixedQuadrupleList

System Interaction types

2-body Extension3-body 4-body N-body LangevinThermostatnon bonded interaction signals signalstemplates VerletList Integrator VelocityVerlet VerletListAdress

VerletListTriple Interaction types have Storage CellListAllPairs to be combined with Interaction potentials BoundaryConditions CellListAllParticlesDomain Decomposition

VerletListInteraction OrthorhombicBC FixedPairList < LennardJones > FixedTripleList

FixedQuadrupleList bonded System interaction templates Potentials

2-body Extension3-body 4-body N-body LangevinThermostatnon bonded interaction signals signalstemplates VerletList Integrator Ewald Cosine Lennard VelocityVerlet KSpace Squared JonesCap VerletListAdress Angular Cosine Lennard FENE Soft Tabulated VerletListTriple Cosine Jones Reaction Storage CellListAllPairs FieldGen Angular Stillinger OPLS Harmonic Harmonic BoundaryConditionsWeber Tabulated CellListAllParticlesDomain Angular Tabulated Ewald Morse Decomposition Dihedral RSpace OrthorhombicBC FixedPairList

FixedTripleList

FixedQuadrupleList bonded System interaction templates Potentials

2-body Extension3-body 4-body N-body LangevinThermostatnon bonded interaction signals signalstemplates VerletList Integrator Ewald Cosine Lennard VelocityVerlet KSpace Squared JonesCap VerletListAdress Angular Cosine Lennard FENE Soft Tabulated VerletListTriple Cosine Jones Reaction Storage CellListAllPairs FieldGen Angular Stillinger OPLS Harmonic Harmonic BoundaryConditionsWeber Tabulated CellListAllParticlesDomain Angular Tabulated Ewald Morse Decomposition Dihedral RSpace OrthorhombicBC FixedPairList

FixedTripleList C++ code: FixedQuadrupleList typedef class VerletListInteractionTemplate bonded < LennardJones > VerletListLennardJonesSystem interaction templates Potentials

2-body Extension3-body 4-body N-body LangevinThermostatnon bonded interaction signals signalstemplates VerletList Integrator Ewald Cosine Lennard VelocityVerlet KSpace Squared JonesCap VerletListAdress Angular Cosine Lennard FENE Soft Tabulated VerletListTriple Cosine Jones Reaction Storage CellListAllPairs FieldGen Angular Stillinger OPLS Harmonic Harmonic BoundaryConditionsWeber Tabulated CellListAllParticlesDomain Angular Tabulated Ewald Morse Decomposition Dihedral RSpace OrthorhombicBC FixedPairList

FixedTripleList C++ code: FixedQuadrupleList typedef class FixedPairListInteractionTemplate bonded < LennardJones > FixedPairListLennardJonesSystem interaction templates Potentials

2-body Extension3-body 4-body N-body LangevinThermostatnon bonded interaction signals signalstemplates VerletList Integrator Ewald Cosine Lennard VelocityVerlet KSpace Squared JonesCap VerletListAdress Angular Cosine Lennard FENE Soft Tabulated VerletListTriple Cosine Jones Reaction Storage CellListAllPairs FieldGen Angular Stillinger OPLS Harmonic Harmonic BoundaryConditionsWeber Tabulated CellListAllParticlesDomain Angular Tabulated Ewald Morse Decomposition Dihedral RSpace OrthorhombicBC FixedPairList

FixedTripleList C++ code: FixedQuadrupleList typedef class VerletListTripleInteractionTemplate bonded < StillingerWeberTripleTerm > VerletListStillingerWeberTripleTermSystem interaction templates Abstract classes

Extension LangevinThermostat

signals signals

Integrator VelocityVerlet

Interaction BoundaryConditions Storage

VerletListInteraction OrthorhombicBC Domain < LennardJones > Decomposition

System Storage

Extension LangevinThermostat • Storage takes care of parallelisation • Distributes particles to the MPI tasks • Updates topology information on all MPI tasks • Sends and receives communication buffers

Particle listssignals for different interactions are updated on signalsStorage signals from DomainDecomposition Integrator VelocityVerlet VerletList Domain Decomposition

VerletListAdress

VerletListTriple signal Interaction BoundaryConditionsonParticlesChanged

FixedPairList signal beforeSendParticles VerletListInteractionFixedTripleList OrthorhombicBC signal < LennardJones > afterRecvParticles FixedQuadrupleList System ESPResSo++ Team: Current developers: • Torsten Stuehn (MPIP) • Vitalii Starchenko (MPIP) • Sebastian Fritsch (MPIP) • Konstantin Koschke (MPIP) • Livia Moreira (MPIP) • Raffaello Potestio (MPIP) • Karsten Kreis (MPIP) • Stas Bevc (NIC, Slovenia) Former developers:

• Thomas Brandes (SCAI) • Dirk Reith (SCAI) • Axel Arnold (ICP) • Olaf Lenz (ICP) • Jonathan Halverson (BNL, USA) • Victor Ruehle (Cambridge, UK) • Christoph Junghans (LANL, USA)

Thank you for your attention !

Project website:

www.espresso-pp.de

ESPResSo++ CECAM Tutorial