Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistent style in samples #1845

Merged
merged 4 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/MDAnalysisIntegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# set up a minimal sample system

system = espressomd.System(box_l=[10.0, 10.0, 10.0])
system.set_random_state_PRNG()
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]
np.random.seed(seed=system.seed)

system.time_step = 0.001
system.cell_system.skin = 0.1

Expand Down
7 changes: 4 additions & 3 deletions samples/billard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from espressomd import electrostatics
from espressomd import minimize_energy
from espressomd.interactions import *
import numpy
import numpy as np
from threading import Thread
from math import *
from espressomd.visualization_opengl import *
Expand All @@ -18,6 +18,7 @@

#ESPRESSO
system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system.seed = system.cell_system.get_state()['n_nodes'] * [1234]
table_dim = [2.24,1.12]
system.box_l = [table_dim[0], 3, table_dim[1]]

Expand All @@ -34,7 +35,7 @@
light_brightness = 5.0)

stopped = True
angle = numpy.pi*0.5
angle = np.pi*0.5
impulse = 10.0

def decreaseAngle():
Expand Down Expand Up @@ -168,7 +169,7 @@ def mix_sig(sig1,sig2,rule='LB'):

vsum = 0
for p in system.part:
vsum += numpy.linalg.norm(p.v)
vsum += np.linalg.norm(p.v)

for h in hole_pos:

Expand Down
51 changes: 26 additions & 25 deletions samples/bonds-tst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import espressomd
from espressomd.interactions import *

S = espressomd.System(box_l=[1.0, 1.0, 1.0])
system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system.seed = system.cell_system.get_state()['n_nodes'] * [1234]

h = HarmonicBond(r_0=0, k=1)
f = FeneBond(k=1, d_r_max=1)
Expand All @@ -14,61 +15,61 @@
print(f2)

# note the order of the printed bond types
S.bonded_inter[0] = h
S.bonded_inter[2] = f
S.bonded_inter.add(f2)
system.bonded_inter[0] = h
system.bonded_inter[2] = f
system.bonded_inter.add(f2)

print("\n**Added bond types to the system:")
for b in S.bonded_inter:
for b in system.bonded_inter:
print(b)

S.part.add(id=0, pos=(0., 0., 0.))
S.part.add(id=1, pos=(0, 0, 0))
S.part.add(id=2, pos=(0, 0, 0))
system.part.add(id=0, pos=(0., 0., 0.))
system.part.add(id=1, pos=(0, 0, 0))
system.part.add(id=2, pos=(0, 0, 0))
print("\n**Defined three particles")
print("Bonds for particle '0':")
print(S.part[0].bonds)
print(system.part[0].bonds)

print("\n**Bonding particle 0 to particle 1 with bond referred by \"f2\'")
S.part[0].add_bond((f2, 1))
system.part[0].add_bond((f2, 1))
print("Bonds for particle '0':")
print(S.part[0].bonds)
print(system.part[0].bonds)


print("\n**Bonding particle 0 to particle 2 with bond referred by index 0")
S.part[0].add_bond((0, 2))
system.part[0].add_bond((0, 2))
print("Bonds for particle 0:")
print(S.part[0].bonds)
print(system.part[0].bonds)

print("Bonds for particle 1:")
print(S.part[1].bonds)
print(system.part[1].bonds)
print("Bonds for particle 2:")
print(S.part[2].bonds)
print(system.part[2].bonds)


print("\n**creating holder for bonds on particle 0")
tmp = S.part[0].bonds
tmp = system.part[0].bonds
print("\n**deleted all bonds of 0")
S.part[0].delete_all_bonds()
system.part[0].delete_all_bonds()
print("Bonds for particle 0:")
print(S.part[0].bonds)
print(system.part[0].bonds)

print("\n**setting particle 0 bonds from holder")
S.part[0].bonds = tmp
system.part[0].bonds = tmp
print("Bonds for particle 0:")
print(S.part[0].bonds)
print(system.part[0].bonds)

print("\n**deleting bond referred by \"h\" to particle 2 :")
S.part[0].delete_bond((h, 2))
system.part[0].delete_bond((h, 2))
print("Bonds for particle '0':")
print(S.part[0].bonds)
print(system.part[0].bonds)

print("\n**Bonding particle 0 to particle 1 with bond referred by index 0 :")
print("**Bonding particle 0 to particle 2 with bond referred by index 2 :")
S.part[0].bonds = ((0, 1), (2, 2))
system.part[0].bonds = ((0, 1), (2, 2))
print("Bonds for particle '0':")
print(S.part[0].bonds)
print(system.part[0].bonds)

print("**Listing bonds held by all particles")
for p in S.part:
for p in system.part:
print(p.bonds)
18 changes: 10 additions & 8 deletions samples/cellsystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
import espressomd as es
import espressomd
from espressomd import polymer
from espressomd import interactions
import time
Expand All @@ -29,31 +29,33 @@
def profile():
cs.skin = skin
ti = time.time()
S.integrator.run(n_steps)
system.integrator.run(n_steps)
tf = time.time()
print("\t with skin={} ran {:d} steps in {:f} seconds. steps/sec:{:f} ".format(skin,
n_steps, tf - ti, n_steps * 1. / (tf - ti)))


S = es.System(box_l = [100, 100, 100])
cs = S.cell_system
system = espressomd.System(box_l = [100, 100, 100])
system.set_random_state_PRNG()
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]
cs = system.cell_system


# domain decomposition with verlet list: three equivalent commands
cs.set_domain_decomposition()
cs.set_domain_decomposition(True)
cs.set_domain_decomposition(use_verlet_lists=True)

S.thermostat.set_langevin(kT=1.0, gamma=1.0)
S.time_step = 0.01
system.thermostat.set_langevin(kT=1.0, gamma=1.0)
system.time_step = 0.01


# Create a minimal polymer
S.non_bonded_inter[0, 0].lennard_jones.set_params(
system.non_bonded_inter[0, 0].lennard_jones.set_params(
epsilon=1, sigma=1,
cutoff=2**(1. / 6), shift="auto")
fene = interactions.FeneBond(k=10, d_r_max=1.5)
S.bonded_inter.add(fene)
system.bonded_inter.add(fene)
polymer.create_polymer(N_P=1, bond_length=0.97, MPC=100, bond=fene)

n_steps = 1000
Expand Down
10 changes: 7 additions & 3 deletions samples/coulomb_debye_hueckel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
import numpy
import numpy as np
import espressomd
from espressomd import thermostat
from espressomd import electrostatics
Expand Down Expand Up @@ -63,6 +63,10 @@
# Integration parameters
#############################################################
system = espressomd.System(box_l=[box_l]*3)
system.set_random_state_PRNG()
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]
np.random.seed(seed=system.seed)

system.time_step = 0.01
system.cell_system.skin = 0.4

Expand Down Expand Up @@ -99,7 +103,7 @@
#############################################################

for i in range(n_part):
system.part.add(id=i, pos=numpy.random.random(3) * system.box_l)
system.part.add(id=i, pos=np.random.random(3) * system.box_l)

for i in range(n_part / 2):
system.part[2 * i].q = -1.0
Expand All @@ -115,7 +119,7 @@
# means that lj_sig is 0.714 nm in SI units.
coulomb_prefactor = 1
# inverse Debye length for 1:1 electrolyte in water at room temperature (nm)
dh_kappa = numpy.sqrt(mol_dens) / 0.304
dh_kappa = np.sqrt(mol_dens) / 0.304
# convert to MD units
dh_kappa = dh_kappa / 0.714
dh = electrostatics.CDH(prefactor=coulomb_prefactor, kappa=dh_kappa,
Expand Down
9 changes: 6 additions & 3 deletions samples/debye_hueckel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
import numpy
import numpy as np
import espressomd
from espressomd import thermostat
from espressomd import electrostatics
Expand Down Expand Up @@ -63,6 +63,9 @@
# Integration parameters
#############################################################
system = espressomd.System(box_l=[box_l]*3)
system.set_random_state_PRNG()
np.random.seed(seed=system.seed)

system.time_step = 0.01
system.cell_system.skin = 0.4

Expand Down Expand Up @@ -99,7 +102,7 @@
#############################################################

for i in range(n_part):
system.part.add(id=i, pos=numpy.random.random(3) * system.box_l)
system.part.add(id=i, pos=np.random.random(3) * system.box_l)

for i in range(n_part / 2):
system.part[2 * i].q = -1.0
Expand All @@ -112,7 +115,7 @@
# means that lj_sig is 0.714 nm in SI units.
coulomb_prefactor =1
# inverse Debye length for 1:1 electrolyte in water at room temperature (nm)
dh_kappa = numpy.sqrt(mol_dens) / 0.304
dh_kappa = np.sqrt(mol_dens) / 0.304
# convert to MD units
dh_kappa = dh_kappa / 0.714
dh = electrostatics.DH(
Expand Down
30 changes: 17 additions & 13 deletions samples/diffusion_coefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
"""

from __future__ import division, print_function
import espressomd
from espressomd.correlators import Correlator
from espressomd.observables import ParticlePositions, ParticleVelocities
import numpy as np

gamma=2.4
kT=1.37
dt=0.05

import espressomd
from espressomd.correlators import Correlator
from espressomd.observables import ParticlePositions, ParticleVelocities
import numpy as np
system=espressomd.System(box_l=[1.0, 1.0, 1.0])
system.set_random_state_PRNG()
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]
np.random.seed(seed=system.seed)


s=espressomd.System(box_l=[1.0, 1.0, 1.0])
p=s.part.add(pos=(0,0,0),id=0)
s.time_step=dt
s.thermostat.set_langevin(kT=kT,gamma=gamma)
s.cell_system.skin =0.4
s.integrator.run(1000)
p=system.part.add(pos=(0,0,0),id=0)
system.time_step=dt
system.thermostat.set_langevin(kT=kT,gamma=gamma)
system.cell_system.skin =0.4
system.integrator.run(1000)

pos_obs=ParticlePositions(ids=(0,))
vel_obs=ParticleVelocities(ids=(0,))
Expand All @@ -31,10 +35,10 @@
corr_operation="square_distance_componentwise", compress1="discard1")
c_vel = Correlator(obs1=vel_obs, tau_lin=16, tau_max=20., dt=dt,
corr_operation="scalar_product", compress1="discard1")
s.auto_update_correlators.add(c_pos)
s.auto_update_correlators.add(c_vel)
system.auto_update_correlators.add(c_pos)
system.auto_update_correlators.add(c_vel)

s.integrator.run(1000000)
system.integrator.run(1000000)

c_pos.finalize()
c_vel.finalize()
Expand Down
23 changes: 13 additions & 10 deletions samples/dpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np

# Set up the box and time step
s = espressomd.System(box_l = 3 * [10])
s.time_step = 0.01
s.cell_system.skin=0.4
system = espressomd.System(box_l = 3 * [10])
system.time_step = 0.01
system.cell_system.skin = 0.4

# DPD parameters
n_part = 200
Expand All @@ -16,31 +16,34 @@
F_max=1.

# Activate the thermostat
s.thermostat.set_dpd(kT=kT)
system.thermostat.set_dpd(kT=kT)
system.set_random_state_PRNG()
np.random.seed(seed=system.seed)
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]

# Set up the DPD friction interaction
s.non_bonded_inter[0,0].dpd.set_params(
system.non_bonded_inter[0,0].dpd.set_params(
weight_function=0, gamma=gamma, r_cut=r_cut,
trans_weight_function=0, trans_gamma=gamma, trans_r_cut=r_cut)

# Set up the repulsive interaction
s.non_bonded_inter[0,0].hat.set_params(F_max=F_max,
system.non_bonded_inter[0,0].hat.set_params(F_max=F_max,
cutoff=r_cut)

# Add the particles randomly distributed over the box
s.part.add(pos=s.box_l * np.random.random((n_part,3)))
system.part.add(pos=system.box_l * np.random.random((n_part,3)))

# As a usage example, we calculate the pressure at serveral
# particle densities.
for V in range(100, 1000, 100):
# Rescale the system to the new volume
s.change_volume_and_rescale_particles(V**0.3333)
system.change_volume_and_rescale_particles(V**0.3333)

# List of samples
p_samples = []
for i in range(100):
s.integrator.run(1000)
p_samples.append(s.analysis.pressure()['total'])
system.integrator.run(1000)
p_samples.append(system.analysis.pressure()['total'])

# Average pressure
p_avg = np.mean(p_samples)
Expand Down
5 changes: 5 additions & 0 deletions samples/ekboundaries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

from espressomd import System, shapes, electrokinetics
import sys

system = System(box_l = [10, 10, 10])
system.set_random_state_PRNG()
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]

system.cell_system.skin = 0.4
system.time_step = 0.1

Expand Down
Loading