Пример #1
0
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/minimal-diamond.py", sim_steps=10)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #2
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

try:
    import pint  # pylint: disable=unused-import
except ImportError:
    tutorial = importlib_wrapper.MagicMock()
    skipIfMissingFeatures = ut.skip(
        "Python module pint not available, skipping test!")
else:
    tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
        "@TUTORIALS_DIR@/constant_pH/constant_pH.py",
        script_suffix="ideal",
        USE_WCA=False,
        USE_ELECTROSTATICS=False,
        NUM_PHS=10)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test(self):
        ref_values = 1. / (1 + 10**(tutorial.pKa - tutorial.pHs))
        sim_values = tutorial.av_alpha
        sim_values_error = tutorial.err_alpha
        # test alpha +/- 0.02 and standard error of alpha less than 0.02
        np.testing.assert_allclose(sim_values, ref_values, rtol=0., atol=0.02)
        np.testing.assert_array_less(sim_values_error, 0.02)
Пример #3
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import pathlib

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/ekboundaries.py", gpu=True, n_int_cycles=50)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system

    def test_file_generation(self):
        # test .vtk files exist
        path_vtk_root = pathlib.Path("ek")
        for basename in [
                "pos_dens_0.vtk", "pos_flux_0.vtk", "ekv_0.vtk",
                "neg_dens_0.vtk", "neg_flux_0.vtk", "ekb_0.vtk"
        ]:
            filepath = path_vtk_root / basename
            self.assertTrue(filepath.is_file(), f"File {filepath} not created")
Пример #4
0
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import os

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/09-swimmer_reactions/SOLUTIONS/reaction.py",
    cmd_arguments=[1],
    equi_steps=250,
    equi_length=10,
    prod_steps=200,
    prod_length=10)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_file_generation(self):
        for name in ["msd_0.dat", "avacf_0.dat"]:
            filepath = os.path.join(tutorial.outdir, name)
            self.assertTrue(os.path.isfile(filepath),
                            filepath + " not created")
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper


def disable_GUI(code):
    # integrate without visualizer
    breakpoint = "visualizer.update()"
    assert breakpoint in code
    code = code.replace(breakpoint, "")
    breakpoint = "t = threading.Thread(target=main_thread)"
    assert breakpoint in code
    code = code.split(breakpoint, 1)[0] + "main_thread()"
    return code


sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/visualization_ljliquid.py",
    substitutions=disable_GUI,
    int_n_times=5)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #6
0
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np


tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/ferrofluid/ferrofluid_part1.py",
    EQUIL_STEPS=200, EQUIL_ROUNDS=10,
    CI_DP3M_PARAMS={'cao': 3, 'r_cut': 8.34, 'mesh': [8, 8, 8], 'alpha': 0.2115, 'tune': False})


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test(self):
        self.assertEqual(
            int(np.sum(tutorial.n_clusters)), len(tutorial.cluster_sizes))
        for i in range(8):
            self.assertLess(
                tutorial.size_dist[0][i + 1],
                tutorial.size_dist[0][i])
Пример #7
0
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np
np.random.seed(41)

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/raspberry_electrophoresis/raspberry_electrophoresis.py",
    gpu=True, box_l=20., num_iterations=20, num_steps_per_iteration=20)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    '''Check the raspberry travels a longer distance on the x-axis'''
    system = tutorial.system

    def test_steepest_descent_convergence(self):
        self.assertLess(tutorial.force_max, 10.)

    def test_trajectory_sample(self):
        trajectory = np.loadtxt('posVsTime_sample.dat')[:, 1:4]
        x, y, z = np.abs(trajectory[-1, :] - trajectory[0, :])
        self.assertGreater(x, y)
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/lattice_boltzmann/lattice_boltzmann_poiseuille_flow.py",
    gpu=True)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_flow_profile(self):
        analytical = tutorial.y_values
        simulation = tutorial.fluid_velocities
        rmsd = np.sqrt(np.mean(np.square(analytical - simulation)))
        self.assertLess(rmsd, 2e-5 * tutorial.AGRID / tutorial.lbf.tau)


if __name__ == "__main__":
Пример #9
0
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper


def shorten_loop(code):
    breakpoint = "while True:"
    assert breakpoint in code
    code = code.replace(breakpoint, "for _ in range(6):", 1)
    return code


sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/load_checkpoint.py", substitutions=shorten_loop)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #10
0
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

# make simulation deterministic
np.random.seed(42)

benchmark, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@BENCHMARKS_DIR@/ferrofluid.py", measurement_steps=100, n_iterations=2,
    cmd_arguments=["--particles_per_core", "400"], min_skin=0.225, max_skin=0.225,
    dp3m_params={'prefactor': 1, 'accuracy': 1e-4, 'cao': 7, 'r_cut': 5.193,
                 'mesh': [20, 20, 20], 'alpha': 0.64788, 'tune': False})


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = benchmark.system


if __name__ == "__main__":
    ut.main()
Пример #11
0
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/p3m.py", int_steps=100, int_n_times=5)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #12
0
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

benchmark, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@BENCHMARKS_DIR@/p3m.py",
    cmd_arguments=["--particles_per_core", "800"],
    n_iterations=2)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = benchmark.system


if __name__ == "__main__":
    ut.main()
Пример #13
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import os

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/active_matter/solutions/rectification_geometry.py")


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_file_generation(self):
        filepath = os.path.join(tutorial.outdir, "boundary.vtk")
        self.assertTrue(os.path.isfile(filepath), filepath + " not created")


if __name__ == "__main__":
    ut.main()
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper as iw
import numpy as np
import sys

# these tutorials need to be executed sequentially
tutorial_simulation, skipIfMissingFeatures_simulation = iw.configure_and_import(
    "@TUTORIALS_DIR@/07-electrokinetics/07-electrokinetics.py",
    gpu=True, integration_length=600, dt=0.5)
tutorial_analytical, skipIfMissingFeatures_plot = iw.configure_and_import(
    "@TUTORIALS_DIR@/07-electrokinetics/scripts/eof_analytical.py")
tutorial_plot, skipIfMissingFeatures_plot = iw.configure_and_import(
    "@TUTORIALS_DIR@/07-electrokinetics/scripts/plot.py")


@skipIfMissingFeatures_simulation
@skipIfMissingFeatures_plot
class Tutorial(ut.TestCase):
    system = tutorial_simulation.system

    def normalize_two_datasets(self, a, b):
        offset = min(np.min(a), np.min(b))
        a -= offset
Пример #15
0
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import os
import numpy as np

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/06-active_matter/SOLUTIONS/rectification_simulation.py",
    cmd_arguments=[6.0],
    prod_steps=80,
    prod_length=100)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_rectification(self):
        x = tutorial.system.part[:].pos[:, 0]
        left_chamber = np.sum(x < tutorial.length / 2.0)
        right_chamber = np.sum(x > tutorial.length / 2.0)
        excess = (right_chamber - left_chamber) * 100. / tutorial.npart
        # expecting at least 5% excess due to rectification
        self.assertGreater(excess, 5.0)
Пример #16
0
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/10-reaction_ensemble/scripts/RE_vs_cpH.py")


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system


if __name__ == "__main__":
    ut.main()
Пример #17
0
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/grand_canonical.py",
    n_int_cycles=51,
    n_int_steps=5,
    warm_n_times=10,
    warm_steps=50,
    cmd_arguments=[0.01, 0.01])


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system

    def test_deviation_to_target_concentration(self):
        # deviation < 10%
        self.assertLess(abs(sample.deviation), 10.0)


if __name__ == "__main__":
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import os

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/active_matter/solutions/flow_field.py", gpu=True,
    cmd_arguments=["pusher", 5.0], PROD_STEPS=100, PROD_LENGTH=50)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_file_generation(self):
        for name in ["trajectory.dat", "position_0.vtk", "lb_velocity_0.vtk"]:
            filepath = os.path.join(tutorial.outdir, name)
            self.assertTrue(
                os.path.isfile(filepath),
                filepath + " not created")

Пример #19
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper


def disable_GUI(code):
    # integrate without visualizer
    breakpoint = "visualizer.run(1)"
    assert breakpoint in code
    code = code.replace(breakpoint, "steps=1\nsystem.integrator.run(steps)", 1)
    return code


sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/visualization_elc.py",
    substitutions=disable_GUI, steps=5000)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system

    def test_dipole_moment(self):
        import espressomd.observables
        obs = espressomd.observables.DipoleMoment(
            ids=self.system.part.all().id)
        dipm = obs.calculate()
        self.assertLess(dipm[2], 0, msg="charges moved in the wrong direction")
        # the dipole moment should be the strongest along the z-axis
        self.assertGreater(abs(dipm[2]), abs(dipm[0]))
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/minimal-charged-particles.py", box_l=6.0, int_steps=100)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #21
0
import unittest as ut
import importlib_wrapper
import numpy as np

# make simulation deterministic
np.random.seed(42)

benchmark, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@BENCHMARKS_DIR@/p3m.py",
    cmd_arguments=["--particles_per_core", "400"],
    measurement_steps=100,
    n_iterations=2,
    min_skin=0.262,
    max_skin=0.262,
    p3m_params={
        'prefactor': 4,
        'accuracy': 1e-4,
        'cao': 7,
        'r_cut': 3.182,
        'mesh': [24, 24, 24],
        'alpha': 1.02742,
        'tune': False
    })


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = benchmark.system


if __name__ == "__main__":
Пример #22
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper


def disable_visualizer_GUI(code):
    breakpoint = "while True:"
    assert breakpoint in code
    code = code.replace(breakpoint, "for _ in range(5):", 1)
    breakpoint = "t = threading.Thread(target=main)"
    assert breakpoint in code
    code = code.split(breakpoint, 1)[0] + "main()"
    return code


sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/billiard.py", substitutions=disable_visualizer_GUI)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #23
0
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/01-lennard_jones/01-lennard_jones.py",
    substitutions=lambda code: code.replace('r_star = ', 'r_star = r #', 1))


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_global_variables(self):
        self.assertLess(tutorial.standard_error_total_energy, 2.5)

    def test_rdf_curve(self):
        self.assertGreater(
            np.corrcoef(tutorial.avg_rdf, tutorial.theo_rdf)[1, 0], 0.985)

Пример #24
0
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/minimal-polymer.py", t_steps=10)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system


if __name__ == "__main__":
    ut.main()
Пример #25
0
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import os

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/active_matter/solutions/enhanced_diffusion.py",
    cmd_arguments=[5.0],
    SAMP_STEPS=500,
    SAMP_LENGTH=100)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_file_generation(self):
        for name in ["msd_{}_0.dat", "vacf_{}_0.dat", "avacf_{}_0.dat"]:
            filepath = os.path.join(tutorial.outdir, name.format(tutorial.vel))
            self.assertTrue(os.path.isfile(filepath),
                            filepath + " not created")

Пример #26
0
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

implementation = "gpu" if "gpu" in "@TEST_LABELS@".split(";") else "cpu"
sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/lbf.py", gpu=implementation == "gpu",
    cmd_arguments=["--" + implementation], script_suffix=implementation)


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system

    def test_electrophoresis_gradient(self):
        # the force is applied along the z-axis
        gradient = np.mean(np.gradient(sample.f_list.T, axis=1), axis=1)
        self.assertAlmostEqual(gradient[0], 0.0, places=11)
        self.assertAlmostEqual(gradient[1], 0.0, places=11)
        self.assertAlmostEqual(gradient[2], -7.66981e-7, places=11)

# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import os

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/06-active_matter/SOLUTIONS/rectification_geometry.py",
    gpu=True)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test_file_generation(self):
        filepath = os.path.join(tutorial.outdir, "boundary.vtk")
        self.assertTrue(os.path.isfile(filepath), filepath + " not created")


if __name__ == "__main__":
    ut.main()
Пример #28
0
import importlib_wrapper
import numpy as np

sd_device = "--gpu" if "gpu" in "@TEST_SUFFIX@" else "--cpu"
sd_method = "--fts" if "fts" in "@TEST_SUFFIX@" else "--ft"
if sd_method == "--fts" and sd_device == "--cpu":
    y_min = -555
    intsteps = 5500
else:
    y_min = -200
    intsteps = 2100

sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@SAMPLES_DIR@/dancing.py",
    script_suffix="@TEST_SUFFIX@",
    gpu=(sd_device == "--gpu"),
    cmd_arguments=[sd_device, sd_method],
    intsteps=intsteps,
    ref_data="@CMAKE_SOURCE_DIR@/testsuite/python/data/dancing.txt")


@skipIfMissingFeatures
class Sample(ut.TestCase):
    system = sample.system

    def test_trajectory(self):
        # compare the simulated and published trajectories
        simul = sample.positions[:, :, 0:2]
        paper = sample.data.reshape([-1, 3, 2])

        for pid in range(3):
Пример #29
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper


def disable_visualizer_GUI(code):
    breakpoint = "t = Thread(target=main)"
    assert breakpoint in code
    code = code.split(breakpoint, 1)[0] + "main()"
    return code


tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
    "@TUTORIALS_DIR@/08-visualization/08-visualization.py",
    substitutions=disable_visualizer_GUI,
    int_n_times=5,
    int_steps=100,
    matplotlib_notebook=False)


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system


if __name__ == "__main__":
    ut.main()
Пример #30
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

try:
    import pint  # pylint: disable=unused-import
except ImportError:
    tutorial = importlib_wrapper.MagicMock()
    skipIfMissingFeatures = ut.skip(
        "Python module pint not available, skipping test!")
else:
    tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
        "@TUTORIALS_DIR@/constant_pH/constant_pH.py", script_suffix="ideal")


@skipIfMissingFeatures
class Tutorial(ut.TestCase):
    system = tutorial.system

    def test(self):
        expected_values = 1. / (1 + 10**(tutorial.pK - tutorial.pHs))
        simulated_values = tutorial.av_alpha
        simulated_values_error = tutorial.err_alpha
        # test alpha +/- 0.05 and standard error of alpha less than 0.05
        np.testing.assert_allclose(expected_values,
                                   simulated_values,
                                   rtol=0,
                                   atol=0.05)