2 # Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 # (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 # the University of Michigan All rights reserved.
6 # HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 # copyright is held, by various Contributors who have granted The Regents of the
8 # University of Michigan the right to modify and/or distribute such Contributions.
10 # You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 # and binary forms, provided you abide by the following conditions:
13 # * Redistributions of source code must retain the above copyright notice, this
14 # list of conditions, and the following disclaimer both in the code and
15 # prominently in any materials provided with the distribution.
17 # * Redistributions in binary form must reproduce the above copyright notice, this
18 # list of conditions, and the following disclaimer in the documentation and/or
19 # other materials provided with the distribution.
21 # * All publications and presentations based on HOOMD-blue, including any reports
22 # or published results obtained, in whole or in part, with HOOMD-blue, will
23 # acknowledge its use according to the terms posted at the time of submission on:
24 # http://codeblue.umich.edu/hoomd-blue/citations.html
26 # * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 # http://codeblue.umich.edu/hoomd-blue/
29 # * Apart from the above required attributions, neither the name of the copyright
30 # holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 # promote products derived from this software without specific prior written
36 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 # WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 from hoomd_plugins
.evaluators_ext_template
import _evaluators_ext_template
52 # Next, since we are extending an pair potential, we need to bring in the base class and some other parts from
54 from hoomd_script
import pair
55 from hoomd_script
import util
56 from hoomd_script
import globals
60 ## Lennard-Jones %pair %force
62 # Here, you can document your pair potential.The following is an abbreviated copy of the docs from hoomd itself.
64 # V_{\mathrm{LJ}}(r) = & 4 \varepsilon \left[ \left( \frac{\sigma}{r} \right)^{12} -
65 # \alpha \left( \frac{\sigma}{r} \right)^{6} \right] & r < r_{\mathrm{cut}} \\
66 # = & 0 & r \ge r_{\mathrm{cut}} \\
69 # The following coefficients must be set per unique %pair of particle types. See hoomd_script.pair or
70 # the \ref page_quick_start for information on how to set coefficients.
71 # - \f$ \varepsilon \f$ - \c epsilon (in energy units)
72 # - \f$ \sigma \f$ - \c sigma (in distance units)
73 # - \f$ \alpha \f$ - \c alpha (unitless)
74 # - <i>optional</i>: defaults to 1.0
75 # - \f$ r_{\mathrm{cut}} \f$ - \c r_cut (in distance units)
76 # - <i>optional</i>: defaults to the global r_cut specified in the %pair command
77 # - \f$ r_{\mathrm{on}} \f$ - \c r_on (in distance units)
78 # - <i>optional</i>: defaults to the global r_cut specified in the %pair command
82 # lj.pair_coeff.set('A', 'A', epsilon=1.0, sigma=1.0)
83 # lj.pair_coeff.set('A', 'B', epsilon=2.0, sigma=1.0, alpha=0.5, r_cut=3.0, r_on=2.0);
84 # lj.pair_coeff.set('B', 'B', epsilon=1.0, sigma=1.0, r_cut=2**(1.0/6.0), r_on=2.0);
85 # lj.pair_coeff.set(['A', 'B'], ['C', 'D'], epsilon=1.5, sigma=2.0)
89 ## Specify the Lennard-Jones %pair %force
91 # This method creates the pair force using the c++ classes exported in module.cc. When creating a new pair force,
92 # one must update the referenced classes here.
93 def __init__(self
, r_cut
, name
=None):
94 util
.print_status_line();
96 # tell the base class how we operate
98 # initialize the base class
99 pair
.pair
.__init
__(self
, r_cut
, name
);
101 # update the neighbor list
102 neighbor_list
= pair
._update
_global
_nlist
(r_cut
);
103 neighbor_list
.subscribe(lambda: self
.log
*self
.get_max_rcut())
105 # create the c++ mirror class
106 if not globals.exec_conf
.isCUDAEnabled():
107 self
.cpp_force
= _evaluators_ext_template
.PotentialPairLJ2(globals.system_definition
, neighbor_list
.cpp_nlist
, self
.name
);
108 self
.cpp_class
= _evaluators_ext_template
.PotentialPairLJ2
;
110 neighbor_list
.cpp_nlist
.setStorageMode(hoomd
.NeighborList
.storageMode
.full
);
111 self
.cpp_force
= _evaluators_ext_template
.PotentialPairLJ2GPU(globals.system_definition
, neighbor_list
.cpp_nlist
, self
.name
);
112 self
.cpp_class
= _evaluators_ext_template
.PotentialPairLJ2GPU
;
113 # you can play with the block size value, set it to any multiple of 32 up to 1024. Use the
114 # lj.benchmark() command to find out which block size performs the fastest
115 self
.cpp_force
.setBlockSize(64);
117 globals.system
.addCompute(self
.cpp_force
, self
.force_name
);
119 # setup the coefficent options
120 self
.required_coeffs
= ['epsilon', 'sigma', 'alpha'];
121 self
.pair_coeff
.set_default_coeff('alpha', 1.0);
123 ## Process the coefficients
125 # The coefficients that the user specifies need not be the same coefficients that get passed as paramters
126 # into your Evaluator. This method processes the named coefficients and turns them into the parameter struct
129 def process_coeff(self
, coeff
):
130 epsilon
= coeff
['epsilon'];
131 sigma
= coeff
['sigma'];
132 alpha
= coeff
['alpha'];
134 lj1
= 4.0 * epsilon
* math
.pow(sigma
, 12.0);
135 lj2
= alpha
* 4.0 * epsilon
* math
.pow(sigma
, 6.0);
136 return hoomd
.make_scalar2(lj1
, lj2
);