Skip to content
dstoeckel edited this page Mar 16, 2015 · 2 revisions

How can I create a molecular dynamics (MD) simulation with water molecules?

When using explicit solvent periodic boundary conditions have to be used.

NOTE: Running the following script in BALLView creates a large number of representations (water molecules) as well. To reduce runnging time set the default representation to 'Line Model' before.

# create an Amber forcefield
af = AmberFF()
# get the molecule
s = getSystem(0)

# get the dimensions of the molecule
bbp = BoundingBoxProcessor()
s.apply(bbp)

# enlarge the box around the molecule by some scalar 
sc = 10.

# enlarge the box by the scalar factor
vl = bbp.getLower() - Vector3(sc)
vu = bbp.getUpper() + Vector3(sc)

# tell the forcefield about being a periodic box
af.options.setBool("periodic_box_enabled", True)
af.options.setVector("periodic_box_lower", vl)
af.options.setVector("periodic_box_upper", vu)

# initialize the forcefield with these options
af.setup(s)

# create the box containing molecule and explicit solvent
b = SimpleBox3()
b.set(vl, vu)

# initialize a small building block, in which the forcefield holds
p = PeriodicBoundary(af)

# fill the entire box (b) with copies of p
p.setBox(b)

# setup
p.setup()

# for graphical representation
new_box = p.getBox()

v1 = new_box.a # get the anchor
v2 = Vector3(new_box.getWidth(), 0, 0)
v3 = Vector3(0, new_box.getHeight(), 0)
v4 = Vector3(0, 0, new_box.getDepth())

colored_box = Box(v1, v2, v3, v4)
colored_box.setColor(ColorRGBA(1, 0, 0, 0.8))
r = Representation()
r.insert(colored_box)

# update the representation
getMainControl().insert(r)
getMainControl().update(r)

getMainControl().updateRepresentationsOf(s)
Clone this wiki locally