Ejemplo n.º 1
0
    def test_p3m_pressure(self):
        pressures_via_virial = []
        pressures_via_volume_scaling = []
        p3m = electrostatics.P3M(
            prefactor=2.0,
            accuracy=1e-3,
            mesh=16,
            cao=6,
            r_cut=1.4941e-01 * self.system.box_l[0])
        self.system.actors.add(p3m)
        print("Tune skin: {}".format(self.system.cell_system.tune_skin(
            min_skin=0.0, max_skin=2.5, tol=0.05, int_steps=100)))

        num_samples = 100
        pressure_via_volume_scaling = pressureViaVolumeScaling(
            self.system, self.kT)
        for i in range(num_samples):
            self.system.integrator.run(100)
            pressures_via_virial.append(
                self.system.analysis.pressure()['total'])
            pressure_via_volume_scaling.measure_pressure_via_volume_scaling()
        pressure_virial = np.mean(pressures_via_virial)
        # deviation should be below 5%
        abs_deviation_in_percent = 100 * abs(
            pressure_virial / pressure_via_volume_scaling.get_result() - 1.0)
        npt.assert_array_less(abs_deviation_in_percent, 5.0)
Ejemplo n.º 2
0
    def test_electrostatics(self):

        from espressomd import electrostatics

        self.system.part[0].pos = [1, 2, 2]
        self.system.part[1].pos = [3, 2, 2]
        self.system.part[0].q = 1
        self.system.part[1].q = -1
        p3m = electrostatics.P3M(prefactor=1.0,
                                 accuracy=9.910945054074526e-08,
                                 mesh=[22, 22, 22],
                                 cao=7,
                                 r_cut=8.906249999999998,
                                 alpha=0.387611049779351,
                                 tune=False)
        self.system.actors.add(p3m)

        # did not verify if this is correct, but looks pretty good (close to
        # 1/2)
        u_p3m = -0.501062398379
        energy = self.system.analysis.energy()
        self.assertAlmostEqual(energy["total"], u_p3m, delta=1e-5)
        self.assertAlmostEqual(energy["kinetic"], 0., delta=1e-7)
        self.assertAlmostEqual(energy["bonded"], 0., delta=1e-7)
        self.assertAlmostEqual(energy["non_bonded"], 0, delta=1e-7)
        self.assertAlmostEqual(energy["coulomb"], u_p3m, delta=1e-7)
        self.system.part[0].q = 0
        self.system.part[1].q = 0
        self.system.part[0].pos = [1, 2, 2]
        self.system.part[1].pos = [5, 2, 2]
Ejemplo n.º 3
0
    def test_elc(self):
        # Make sure, the data satisfies the gap
        for p in self.S.part:
            if p.pos[2] < 0 or p.pos[2] > 9.:
                raise Exception("Particle z pos invalid")

        self.S.cell_system.set_domain_decomposition()
        self.S.cell_system.node_grid = sorted(
            self.S.cell_system.node_grid, key=lambda x: -x)
        self.S.periodicity = [1, 1, 1]
        self.S.box_l = (10, 10, 10)

        p3m = electrostatics.P3M(prefactor=1, accuracy=1e-6, mesh=(64, 64, 64))
        elc = electrostatics.ELC(p3m_actor=p3m, maxPWerror=1E-6, gap_size=1)

        self.S.actors.add(elc)
        self.S.integrator.run(0)
        self.compare("elc", energy=True)
Ejemplo n.º 4
0
        def test_zz_p3mElc(self):
            # Make sure, the data satisfies the gap 
            for p in self.S.part:
                if p.pos[2]<0 or p.pos[2]>9.:
                    raise Exception("Particle z pos invalid")
            
            self.S.cell_system.set_domain_decomposition()
            self.S.cell_system.node_grid = self.buf_node_grid 
            self.S.periodicity=1,1,1
            self.S.box_l = (10, 10, 10)

            p3m=el.P3M(prefactor=1, accuracy = 1e-6,mesh=(64,64,64))
            
            self.S.actors.add(p3m)
            elc=el_ext.ELC(maxPWerror=1E-6,gap_size=1)
            self.S.actors.add(elc)
            self.S.integrator.run(0)
            self.compare("elc", energy=True)
            self.S.actors.remove(p3m)
Ejemplo n.º 5
0
    def test_finite_potential_drop(self):
        s = self.system

        p1 = s.part.add(pos=GAP + [0, 0, 1], q=+1)
        p2 = s.part.add(pos=GAP + [0, 0, 9], q=-1)

        s.actors.add(
            electrostatics.P3M(
                # zero is not allowed
                prefactor=1e-100,
                mesh=32,
                cao=5,
                accuracy=1e-3,
            ))

        s.actors.add(
            electrostatic_extensions.ELC(
                gap_size=GAP[2],
                maxPWerror=1e-3,
                delta_mid_top=-1,
                delta_mid_bot=-1,
                const_pot=1,
                pot_diff=POTENTIAL_DIFFERENCE,
            ))

        # Calculated energy
        U_elc = s.analysis.energy()['coulomb']

        # Expected E-Field is voltage drop over the box
        E_expected = POTENTIAL_DIFFERENCE / (BOX_L[2] - GAP[2])
        # Expected potential is -E_expected * z, so
        U_expected = -E_expected * (p1.pos[2] * p1.q + p2.pos[2] * p2.q)

        self.assertAlmostEqual(U_elc, U_expected)

        s.integrator.run(0)
        self.assertAlmostEqual(E_expected, p1.f[2] / p1.q)
        self.assertAlmostEqual(E_expected, p2.f[2] / p2.q)
Ejemplo n.º 6
0
        return ValueError("No combination rule defined")


# Lennard-Jones interactions parameters
for s in [["Cl", "Na"], ["Cl", "Cl"], ["Na", "Na"]]:
    lj_sig = combination_rule_sigma("Berthelot", lj_sigmas[s[0]],
                                    lj_sigmas[s[1]])
    lj_cut = combination_rule_sigma("Berthelot", lj_cuts[s[0]], lj_cuts[s[1]])
    lj_eps = combination_rule_epsilon("Lorentz", lj_epsilons[s[0]],
                                      lj_epsilons[s[1]])

    system.non_bonded_inter[types[s[0]], types[s[1]]].lennard_jones.set_params(
        epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

print("\n--->Tuning Electrostatics")
p3m = electrostatics.P3M(prefactor=l_bjerrum, accuracy=1e-2)
system.actors.add(p3m)


def main():

    print("\n--->Temperature Equilibration")
    system.time = 0.0
    for i in range(num_steps_equilibration):
        energy = system.analysis.energy()
        temp_measured = energy['kinetic'] / ((3.0 / 2.0) * n_part)
        print("t={0:.1f}, E_total={1:.2f}, E_coulomb={2:.2f}, T_cur={3:.4f}".
              format(system.time, energy['total'], energy['coulomb'],
                     temp_measured))
        system.integrator.run(100)
        visualizer.update()
Ejemplo n.º 7
0
act_min_dist = system.analysis.min_dist()
print("Start with minimal distance {}".format(act_min_dist))

system.cell_system.max_num_cells = 14**3

# Assign charges to particles
for i in range(n_part // 2 - 1):
    system.part[2 * i].q = -1.0
    system.part[2 * i + 1].q = 1.0

# P3M setup after charge assignment
#############################################################

print("\nSCRIPT--->Create p3m\n")
#p3m = electrostatics.P3M_GPU(prefactor=2.0, accuracy=1e-2)
p3m = electrostatics.P3M(prefactor=1.0, accuracy=1e-2)

print("\nSCRIPT--->Add actor\n")
system.actors.add(p3m)

print("\nSCRIPT--->P3M parameter:\n")
p3m_params = p3m.get_params()
for key in list(p3m_params.keys()):
    print("{} = {}".format(key, p3m_params[key]))

print("\nSCRIPT--->Explicit tune call\n")
p3m.tune(accuracy=1e3)

print("\nSCRIPT--->P3M parameter:\n")
p3m_params = p3m.get_params()
for key in list(p3m_params.keys()):
Ejemplo n.º 8
0
    sys.stdout.flush()
    system.integrator.run(integ_steps)
    ljcap+=5
 
system.force_cap = 0

#let the colloid move now that bad overlaps have been eliminated
for i in range(n_col_part):
    system.part[i].fix=np.zeros(3,dtype=np.int)

# Turning on the electrostatics
errorCoulomb = 0.01
print("\n# p3m starting...")
sys.stdout.flush()
bjerrum = 2.
p3m = electrostatics.P3M(bjerrum_length=bjerrum, accuracy=0.001)
system.actors.add(p3m)
print("# p3m started!")

system.time_step=time_step

#note that it is important to set all of the particle velocities to zero just before initializing the LB so that the total system momentum is zero
system.galilei.kill_particle_motion()

system.thermostat.turn_off()
lb=espressomd.lb.LBFluidGPU(dens=1., visc=3., agrid=1., tau=time_step, fric=20)
system.actors.add(lb)


#replace the Langevin thermostat with the lb thermostat
system.thermostat.set_lb(kT=1.)
Ejemplo n.º 9
0
# Lennard-Jones interactions parameters
for i in range(len(species)):
    for j in range(i, len(species)):
        s = [species[i], species[j]]
        lj_sig = combination_rule_sigma(
            "Berthelot", lj_sigmas[s[0]], lj_sigmas[s[1]])
        lj_cut = combination_rule_sigma(
            "Berthelot", lj_cuts[s[0]], lj_cuts[s[1]])
        lj_eps = combination_rule_epsilon(
            "Lorentz", lj_epsilons[s[0]], lj_epsilons[s[1]])

        system.non_bonded_inter[types[s[0]], types[s[1]]].lennard_jones.set_params(
            epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

energy = system.analysis.energy()
print("Before Minimization: E_total = {}".format(energy['total']))
system.minimize_energy.init(f_max=1000, gamma=30.0,
                            max_steps=1000, max_displacement=0.01)
system.minimize_energy.minimize()
energy = system.analysis.energy()
print("After Minimization: E_total = {}".format(energy['total']))

print("Tune p3m")
p3m = electrostatics.P3M(prefactor=coulomb_prefactor, accuracy=1e-1)
system.actors.add(p3m)

system.thermostat.set_langevin(kT=temperature, gamma=2.0)

visualizer.run(1)
Ejemplo n.º 10
0
                                    lj_sigmas[s[1]])
    lj_cut = combination_rule_sigma("Berthelot", lj_cuts[s[0]], lj_cuts[s[1]])
    lj_eps = combination_rule_epsilon("Lorentz", lj_epsilons[s[0]],
                                      lj_epsilons[s[1]])

    system.non_bonded_inter[types[s[0]], types[s[1]]].lennard_jones.set_params(
        epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

system.minimize_energy.init(f_max=10,
                            gamma=10,
                            max_steps=2000,
                            max_displacement=0.1)
system.minimize_energy.minimize()

print("\n--->Tuning Electrostatics")
p3m = electrostatics.P3M(bjerrum_length=l_bjerrum, accuracy=1e-2)
system.actors.add(p3m)
elc = electrostatic_extensions.ELC(gap_size=elc_gap, maxPWerror=1e-3)
system.actors.add(elc)


def increaseElectricField():
    global Ez
    Ez += 1000
    for p in system.part:
        p.ext_force = [0, 0, Ez * p.q]
    print(Ez)


def decreaseElectricField():
    global Ez
Ejemplo n.º 11
0
def main():

    print("\n--->Setup system")

    # System parameters
    n_ppside = 10
    n_part = int(n_ppside**3)
    n_ionpairs = n_part / 2
    density = 1.5736
    time_step = 0.001823
    temp = 298.0
    gamma = 20.0
    #l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T)
    l_bjerrum = 130878.0 / temp

    num_steps_equilibration = 3000
    num_configs = 50
    integ_steps_per_config = 500

    # Particle parameters
    types = {"Cl": 0, "Na": 1}
    numbers = {"Cl": n_ionpairs, "Na": n_ionpairs}
    charges = {"Cl": -1.0, "Na": 1.0}
    lj_sigmas = {"Cl": 3.85, "Na": 2.52}
    lj_epsilons = {"Cl": 192.45, "Na": 17.44}

    lj_cuts = {"Cl": 3.0 * lj_sigmas["Cl"], "Na": 3.0 * lj_sigmas["Na"]}

    masses = {"Cl": 35.453, "Na": 22.99}

    # Setup System
    box_l = (n_ionpairs * sum(masses.values()) / density)**(1. / 3.)
    system.box_l = [box_l, box_l, box_l]
    system.periodicity = [1, 1, 1]
    system.time_step = time_step
    system.cell_system.skin = 0.3
    system.thermostat.set_langevin(kT=temp, gamma=gamma)

    # Place particles
    q = 1
    l = box_l / n_ppside
    for i in range(n_ppside):
        for j in range(n_ppside):
            for k in range(n_ppside):
                p = numpy.array([i, j, k]) * l
                if q < 0:
                    system.part.add(id=len(system.part),
                                    type=types["Cl"],
                                    pos=p,
                                    q=charges["Cl"],
                                    mass=masses["Cl"])
                else:
                    system.part.add(id=len(system.part),
                                    type=types["Na"],
                                    pos=p,
                                    q=charges["Na"],
                                    mass=masses["Na"])

                q *= -1
            q *= -1
        q *= -1

    def combination_rule_epsilon(rule, eps1, eps2):
        if rule == "Lorentz":
            return (eps1 * eps2)**0.5
        else:
            return ValueError("No combination rule defined")

    def combination_rule_sigma(rule, sig1, sig2):
        if rule == "Berthelot":
            return (sig1 + sig2) * 0.5
        else:
            return ValueError("No combination rule defined")

# Lennard-Jones interactions parameters

    for s in [["Cl", "Na"], ["Cl", "Cl"], ["Na", "Na"]]:
        lj_sig = combination_rule_sigma("Berthelot", lj_sigmas[s[0]],
                                        lj_sigmas[s[1]])
        lj_cut = combination_rule_sigma("Berthelot", lj_cuts[s[0]],
                                        lj_cuts[s[1]])
        lj_eps = combination_rule_epsilon("Lorentz", lj_epsilons[s[0]],
                                          lj_epsilons[s[1]])

        system.non_bonded_inter[types[s[0]],
                                types[s[1]]].lennard_jones.set_params(
                                    epsilon=lj_eps,
                                    sigma=lj_sig,
                                    cutoff=lj_cut,
                                    shift="auto")

    print("\n--->Tuning Electrostatics")
    #p3m = electrostatics.P3M(bjerrum_length=l_bjerrum, accuracy=1e-2, mesh=[84,84,84], cao=6)
    p3m = electrostatics.P3M(bjerrum_length=l_bjerrum, accuracy=1e-2)
    system.actors.add(p3m)

    print("\n--->Temperature Equilibration")
    system.time = 0.0
    for i in range(int(num_steps_equilibration / 100)):
        energy = system.analysis.energy()
        temp_measured = energy['kinetic'] / ((3.0 / 2.0) * n_part)
        print("t={0:.1f}, E_total={1:.2f}, E_coulomb={2:.2f}, T_cur={3:.4f}".
              format(system.time, energy['total'], energy['coulomb'],
                     temp_measured))
        system.integrator.run(100)
        visualizer.update()

    print("\n--->Integration")
    system.time = 0.0
    while (True):
        system.integrator.run(1)
        visualizer.update()
Ejemplo n.º 12
0
print("After Minimization: E_total = {}".format(energy["total"]))

system.integrator.set_vv()
system.thermostat.set_langevin(kT=1.0, gamma=1.0, seed=42)

# tuning and equilibration
system.integrator.run(min(3 * measurement_steps, 1000))
print("Tune skin: {}".format(
    system.cell_system.tune_skin(min_skin=0.4,
                                 max_skin=1.6,
                                 tol=0.05,
                                 int_steps=100,
                                 adjust_max_skin=True)))
system.integrator.run(min(3 * measurement_steps, 3000))
print("Tune p3m")
p3m = electrostatics.P3M(prefactor=args.prefactor, accuracy=1e-4)
system.actors.add(p3m)
system.integrator.run(min(3 * measurement_steps, 3000))
print("Tune skin: {}".format(
    system.cell_system.tune_skin(min_skin=1.0,
                                 max_skin=1.6,
                                 tol=0.05,
                                 int_steps=100,
                                 adjust_max_skin=True)))

if not args.visualizer:
    # print initial energies
    energies = system.analysis.energy()
    print(energies)

    # time integration loop
Ejemplo n.º 13
0
for i in range(N0):
    system.part.add(id=i, pos=np.random.random(3) * system.box_l, type=1, q=-1)
for i in range(N0, 2 * N0):
    system.part.add(id=i, pos=np.random.random(3) * system.box_l, type=2, q=1)

lj_eps = 1.0
lj_sig = 1.0
lj_cut = 2**(1.0 / 6)
types = [0, 1, 2]
for type_1 in types:
    for type_2 in types:
        system.non_bonded_inter[type_1, type_2].lennard_jones.set_params(
            epsilon=lj_eps, sigma=lj_sig,
            cutoff=lj_cut, shift="auto")

p3m = electrostatics.P3M(prefactor=0.9, accuracy=1e-3)
system.actors.add(p3m)
p3m_params = p3m.get_params()
for key in list(p3m_params.keys()):
    print("{} = {}".format(key, p3m_params[key]))

# Warmup
#############################################################
# warmup integration (with capped LJ potential)
warm_steps = 1000
warm_n_times = 20
# do the warmup until the particles have at least the distance min_dist
# set LJ cap
lj_cap = 20
system.force_cap = lj_cap
Ejemplo n.º 14
0
for i in range(nHCl):
    system.part.add(pos=np.random.random(3) * system.box_l,
                    type=type_Cl,
                    q=charges[type_Cl])

# setting up LJ-interactions
for i in range(1, 5):
    for j in range(i + 1, 6):
        system.non_bonded_inter[i, j].lennard_jones.set_params(epsilon=lj_eps,
                                                               sigma=lj_sig,
                                                               cutoff=lj_cut,
                                                               shift=lj_shift)

# Setting up electrostatics
#
p3m = electrostatics.P3M(prefactor=l_bjerrum * temperature, accuracy=1e-3)
system.actors.add(p3m)

K_diss = 0.002694
K_w = 10.**(-14) * 0.02694**2
RE = None
if (mode == "reaction_ensemble"):
    RE = reaction_ensemble.ReactionEnsemble(temperature=temperature,
                                            exclusion_radius=1,
                                            seed=3)
elif (mode == "constant_pH_ensemble"):
    RE = reaction_ensemble.ConstantpHEnsemble(temperature=temperature,
                                              exclusion_radius=1,
                                              seed=3)
    RE.constant_pH = 0
Ejemplo n.º 15
0
energy = system.analysis.energy()
print("After Minimization: E_total = {}".format(energy["total"]))

system.integrator.set_vv()
system.thermostat.set_langevin(kT=1.0, gamma=1.0, seed=42)

# tuning and equilibration
system.integrator.run(min(3 * measurement_steps, 1000))
print("Tune skin: {}".format(
    system.cell_system.tune_skin(min_skin=0.4,
                                 max_skin=1.6,
                                 tol=0.05,
                                 int_steps=100)))
system.integrator.run(min(3 * measurement_steps, 3000))
print("Tune p3m")
p3m = electrostatics.P3M(prefactor=args.bjerrum_length, accuracy=1e-4)
system.actors.add(p3m)
system.integrator.run(min(3 * measurement_steps, 3000))
print("Tune skin: {}".format(
    system.cell_system.tune_skin(min_skin=1.0,
                                 max_skin=1.6,
                                 tol=0.05,
                                 int_steps=100)))

if not args.visualizer:
    # print initial energies
    energies = system.analysis.energy()
    print(energies)

    # time integration loop
    print("Timing every {} steps".format(measurement_steps))
Ejemplo n.º 16
0
lj_cut = 2.**(1. / 6.)
system.non_bonded_inter[0, 0].lennard_jones.set_params(
    epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")
system.non_bonded_inter[1, 0].lennard_jones.set_params(
    epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")
system.non_bonded_inter[1, 1].lennard_jones.set_params(
    epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

# Check if electrostatics method is clear...
if method not in implemented_methods:
    print("Please select an electrostatics method in the script.")
    exit()

# Distinguish between different methods
if method == "p3m":
    p3m = electrostatics.P3M(bjerrum_length=10.0, accuracy=1e-3)
    system.actors.add(p3m)
    print("P3M parameter:\n")
    p3m_params = p3m.get_params()
    for key in p3m_params.keys():
        print("{} = {}".format(key, p3m_params[key]))
# elif method == "memd":
    # TODO

if "ROTATION" in code_info.features():
    deg_free = 6
else:
    deg_free = 3

# Integration parameters
integ_steps = 200