From 469107c247519acb2a80175d6b2795c4367da63c Mon Sep 17 00:00:00 2001 From: Michael Howard Date: Tue, 28 May 2024 14:14:38 -0500 Subject: [PATCH] Remove pair.spline --- src/PairEvaluatorSpline.h | 111 --------------------- src/PairPotentialSpline.cu | 18 ---- src/PairPotentials.h | 1 - src/module.cc | 1 - src/pair.py | 74 -------------- src/pytest/test_pair_spline.py | 171 --------------------------------- 6 files changed, 376 deletions(-) delete mode 100644 src/PairEvaluatorSpline.h delete mode 100644 src/PairPotentialSpline.cu delete mode 100644 src/pytest/test_pair_spline.py diff --git a/src/PairEvaluatorSpline.h b/src/PairEvaluatorSpline.h deleted file mode 100644 index d1652aef..00000000 --- a/src/PairEvaluatorSpline.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2018-2020, Michael P. Howard -// Copyright (c) 2021-2022, Auburn University -// This file is part of the azplugins project, released under the Modified BSD License. - -/*! - * \file PairEvaluatorSpline.h - * \brief Defines the pair force evaluator class for a spline pair potential - */ - -#ifndef AZPLUGINS_PAIR_EVALUATOR_SPLINE_H_ -#define AZPLUGINS_PAIR_EVALUATOR_SPLINE_H_ - -#include "PairEvaluator.h" - -#ifdef NVCC -#define DEVICE __device__ -#else -#define DEVICE -#endif - -namespace azplugins -{ - -namespace detail -{ - -//! Class for evaluating a spline pair potential -/*! This evaluator calculates the following function: - * \begin{eqnarray*} - * V(r) = & a & r < r_{\rm s}\\ - * = & a*(r_{\rm on}**2-r**2)^m * (r_{\rm cut}^2 + m*r**2 - (m+1)*r_{\rm on}^2) - * / (r_{\rm cut}^2-r_{\rm on}**2)**(m+1) & r_{\rm on} - (const pair_args_t& pair_args, - const typename azplugins::detail::PairEvaluatorSpline::param_type *d_params); - -} // end namespace gpu -} // end namespace azplugins diff --git a/src/PairPotentials.h b/src/PairPotentials.h index 8d506a57..c1df4428 100644 --- a/src/PairPotentials.h +++ b/src/PairPotentials.h @@ -33,7 +33,6 @@ #include "PairEvaluatorAshbaugh.h" #include "PairEvaluatorColloid.h" #include "PairEvaluatorHertz.h" -#include "PairEvaluatorSpline.h" /* * The code below handles python exports using a templated function, and so diff --git a/src/module.cc b/src/module.cc index 48f174d8..3b989943 100644 --- a/src/module.cc +++ b/src/module.cc @@ -192,7 +192,6 @@ PYBIND11_MODULE(_azplugins, m) azplugins::detail::export_ashbaugh_params(m); azplugins::detail::export_pair_potential(m, "PairPotentialColloid"); azplugins::detail::export_pair_potential(m, "PairPotentialHertz"); - azplugins::detail::export_pair_potential(m, "PairPotentialSpline"); /* Anisotropic pair potentials */ azplugins::detail::export_aniso_pair_potential(m, "AnisoPairPotentialTwoPatchMorse"); diff --git a/src/pair.py b/src/pair.py index 9765d7e9..e7293f1d 100644 --- a/src/pair.py +++ b/src/pair.py @@ -11,13 +11,11 @@ ashbaugh colloid hertz - spline two_patch_morse .. autoclass:: ashbaugh .. autoclass:: colloid .. autoclass:: hertz -.. autoclass:: spline .. autoclass:: two_patch_morse """ @@ -277,78 +275,6 @@ def __init__(self, r_cut, nlist, name=None): def process_coeff(self, coeff): return coeff['epsilon'] -class spline(hoomd.md.pair.pair): - R""" Spline potential - - Args: - r_cut (float): Default cutoff radius (in distance units). - nlist (:py:mod:`hoomd.md.nlist`): Neighbor list - name (str): Name of the force instance. - - :py:class:`spline` is a spline potential of the form: - - .. math:: - :nowrap: - - \begin{eqnarray*} - V(r) = & a &, r < r_{\rm s}\\ - = & \frac{a(r_{\rm s}^2-r^2)^m (r_{\rm cut}^2 + m r^2 - (m+1) r_{\rm s}^2)}{(r_{\rm cut}^2-r_{\rm s}^2)^{m+1}} &, r_{\rm s} < r < r_{\rm cut} \\ - = & 0 &, r \ge r_{\rm cut} - \end{eqnarray*} - - Here, :math:`a` is the amplitude :math:`m`, the exponent, :math:`r_{\rm s}` and :math: `r_{\rm cut}` are the cutoff distances. The potential goes smoothly from a value of `a` at `r_{\rm s}` to zero at - `r_{\rm cut}`. The slope is determined by the exponent `m`, which needs to be greater or equal to 2. - The force goes to zero at both the cutoff value `r_{\rm cut}` and `r_{\rm s}`. - - The following coefficients must be set per unique pair of particle types: - - - :math:`a` - *amp* - value of the plateau (in energy units) - - :math:`m` - *exponent* - - :math:`r_{\mathrm{cut}}` - *r_cut* (in distance units) - - *optional*: defaults to the global r_cut specified in the pair command - - :math:`r_{\mathrm{s}}`- *r_start* (in distance units) value where the potential reaches its plateau value - - Example:: - - nl = hoomd.md.nlist.cell() - s = azplugins.pair.spline(r_cut=3.0, nlist=nl) - s.pair_coeff.set('A', 'A', amp=1.0, r_start=1.0, m=2.0) - s.pair_coeff.set(['A','B'], 'B', amp=1.0, r_start=1.0, m=2.0, r_cut=3.0) - - """ - def __init__(self, r_cut, nlist, name=None): - hoomd.util.print_status_line() - - # initialize the base class - hoomd.md.pair.pair.__init__(self, r_cut, nlist, name) - - # create the c++ mirror class - if not hoomd.context.exec_conf.isCUDAEnabled(): - self.cpp_class = _azplugins.PairPotentialSpline - else: - self.cpp_class = _azplugins.PairPotentialSplineGPU - self.nlist.cpp_nlist.setStorageMode(_md.NeighborList.storageMode.full) - self.cpp_force = self.cpp_class(hoomd.context.current.system_definition, self.nlist.cpp_nlist, self.name) - - hoomd.context.current.system.addCompute(self.cpp_force, self.force_name) - - # setup the coefficent options - self.required_coeffs = ['amp', 'm', 'r_start'] - self.r_cut=r_cut - - def process_coeff(self, coeff): - amplitude = coeff['amp'] - exponent = coeff['m'] - r_start = coeff['r_start'] - r_start_sq = r_start*r_start - if exponent<2.0: - hoomd.context.msg.error('azplugins.pair.spline: Exponent for spline needs to be >= 2.\n') - raise ValueError('Exponent for spline needs to be >= 2') - if r_start>=self.r_cut: - hoomd.context.msg.error('azplugins.pair.spline: r_start needs to be smaller than r_cut.\n') - raise ValueError('r_start needs to be smaller than r_cut') - return _hoomd.make_scalar3(amplitude, exponent,r_start_sq) - class two_patch_morse(hoomd.md.pair.ai_pair): R""" Two patches with Morse potential diff --git a/src/pytest/test_pair_spline.py b/src/pytest/test_pair_spline.py deleted file mode 100644 index 4acbbbd1..00000000 --- a/src/pytest/test_pair_spline.py +++ /dev/null @@ -1,171 +0,0 @@ -# Copyright (c) 2018-2020, Michael P. Howard -# Copyright (c) 2021-2022, Auburn University -# This file is part of the azplugins project, released under the Modified BSD License. - -import hoomd -from hoomd import md -hoomd.context.initialize() -try: - from hoomd import azplugins -except ImportError: - import azplugins -import unittest - -# azplugins.pair.spline -class pair_spline_tests(unittest.TestCase): - def setUp(self): - # raw snapshot is fine, just needs to have the types - snap = hoomd.data.make_snapshot(N=100, box=hoomd.data.boxdim(L=20), particle_types=['A']) - self.s = hoomd.init.read_snapshot(snap) - self.nl = md.nlist.cell() - hoomd.context.current.sorter.set_params(grid=8) - - # basic test of creation - def test(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A', 'A', amp=1.0, m=2.0, r_start=1.5) - spline.update_coeffs() - - # test missing ron coefficient - def test_set_missing_ron(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A', 'A', amp=1.0, m=2.0) - self.assertRaises(RuntimeError, spline.update_coeffs) - - # test missing a coefficient - def test_set_missing_amp(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A', 'A', m=3.0, r_start=1.0) - self.assertRaises(RuntimeError, spline.update_coeffs) - - # test missing delta coefficient - def test_set_missing_m(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A', 'A', amp=0.3, r_start=1.0) - self.assertRaises(RuntimeError, spline.update_coeffs) - - # test missing type coefficients - def test_missing_AA(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - self.assertRaises(RuntimeError, spline.update_coeffs) - - # test max rcut - def test_max_rcut(self): - spline = azplugins.pair.spline(r_cut=2.5, nlist = self.nl) - spline.pair_coeff.set('A', 'A', amp=1.0, m=3.0, r_start=1.0) - self.assertAlmostEqual(2.5, spline.get_max_rcut()) - spline.pair_coeff.set('A', 'A', r_cut = 2.0) - self.assertAlmostEqual(2.0, spline.get_max_rcut()) - - # test specific nlist subscription - def test_nlist_subscribe(self): - spline = azplugins.pair.spline(r_cut=2.5, nlist = self.nl) - - spline.pair_coeff.set('A', 'A', amp=1.0, m=2.5, r_start=1.0) - self.nl.update_rcut() - self.assertAlmostEqual(2.5, self.nl.r_cut.get_pair('A','A')) - - spline.pair_coeff.set('A', 'A', r_cut = 2.0) - self.nl.update_rcut() - self.assertAlmostEqual(2.0, self.nl.r_cut.get_pair('A','A')) - - # test coeff list - def test_coeff_list(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set(['A', 'B'], ['A', 'C'], amp=1.0, m=3.0, r_cut=2.5, r_start=2.0) - spline.update_coeffs() - - # test adding types - def test_type_add(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A', 'A', amp=1.0, m=3.0, r_start=1.0) - self.s.particles.types.add('B') - self.assertRaises(RuntimeError, spline.update_coeffs) - spline.pair_coeff.set('A', 'B', amp=1.0, m=3.0, r_start=1.0) - spline.pair_coeff.set('B', 'B', amp=1.0, m=3.0, r_start=1.0) - spline.update_coeffs() - - def tearDown(self): - del self.s, self.nl - hoomd.context.initialize() - -# test the validity of the pair potential -class potential_spline_tests(unittest.TestCase): - def setUp(self): - snap = hoomd.data.make_snapshot(N=2, box=hoomd.data.boxdim(L=20),particle_types=['A']) - if hoomd.comm.get_rank() == 0: - snap.particles.position[0] = (0,0,0) - snap.particles.position[1] = (2.0,0,0) - hoomd.init.read_snapshot(snap) - self.nl = md.nlist.cell() - - # test the calculation of force and potential - def test_potential(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A','A', m=2.0, amp=0.3, r_start=1.0) - - md.integrate.mode_standard(dt=0) - nve = md.integrate.nve(group = hoomd.group.all()) - hoomd.run(1) - U = 0.205005 - F = 0.211059 - f0 = spline.forces[0].force - f1 = spline.forces[1].force - e0 = spline.forces[0].energy - e1 = spline.forces[1].energy - - self.assertAlmostEqual(e0,0.5*U,3) - self.assertAlmostEqual(e1,0.5*U,3) - - self.assertAlmostEqual(f0[0],-F,3) - self.assertAlmostEqual(f0[1],0) - self.assertAlmostEqual(f0[2],0) - - self.assertAlmostEqual(f1[0],F,3) - self.assertAlmostEqual(f1[1],0) - self.assertAlmostEqual(f1[2],0) - - def test_potential_zero(self): - spline = azplugins.pair.spline(r_cut=1.5, nlist = self.nl) - spline.pair_coeff.set('A','A', m=2.0, amp=0.3, r_start=1.0) - - md.integrate.mode_standard(dt=0) - nve = md.integrate.nve(group = hoomd.group.all()) - hoomd.run(1) - U = 0.0 - F = 0.0 - f0 = spline.forces[0].force - f1 = spline.forces[1].force - e0 = spline.forces[0].energy - e1 = spline.forces[1].energy - - self.assertAlmostEqual(e0,0.5*U,3) - self.assertAlmostEqual(e1,0.5*U,3) - self.assertAlmostEqual(f0[0],-F,3) - self.assertAlmostEqual(f1[0],F,3) - - def test_potential_plateau(self): - spline = azplugins.pair.spline(r_cut=3.0, nlist = self.nl) - spline.pair_coeff.set('A','A', m=2.0, amp=-0.389, r_start=2.5) - - md.integrate.mode_standard(dt=0) - nve = md.integrate.nve(group = hoomd.group.all()) - hoomd.run(1) - U = -0.389 - F = 0.0 - f0 = spline.forces[0].force - f1 = spline.forces[1].force - e0 = spline.forces[0].energy - e1 = spline.forces[1].energy - - self.assertAlmostEqual(e0,0.5*U,3) - self.assertAlmostEqual(e1,0.5*U,3) - self.assertAlmostEqual(f0[0],-F,3) - self.assertAlmostEqual(f1[0],F,3) - - def tearDown(self): - del self.nl - hoomd.context.initialize() - -if __name__ == '__main__': - unittest.main(argv = ['test.py', '-v'])