Enable parallel tests.
[hoomd-blue.git] / share / hoomd / plugin_template_evaluators_ext / pymodule / bond.py
blob51f77fef458f31bc786bd975b2c52a5d1f446cae
1 # -- start license --
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
32 # permission.
34 # Disclaimer
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.
48 # -- end license --
50 from hoomd_plugins.evaluators_ext_template import _evaluators_ext_template
52 # Next, since we are extending a bond potential, we need to bring in the base class and some other parts from
53 # hoomd_script
54 from hoomd_script import util
55 from hoomd_script import globals
56 from hoomd_script.bond import _bond
57 import hoomd
58 import math
61 ## Composite of harmonic %bond force with a DPD pair potential
63 # The command bond.harmonic_dpd specifies a %harmonic_dpd potential energy between every bonded %pair of particles
64 # in the simulation.
65 # \f[ V(r) = \frac{1}{2} k \left( r - r_0 \right)^2 + V_{\mathrm{DPD}}(r) \f]
66 # where \f$ \vec{r} \f$ is the vector pointing from one particle to the other
67 # in the %pair and
69 # \f{eqnarray*}
70 # V_{\mathrm{DPD}}(r) = & A \cdot \left( r_{\mathrm{cut}} - r \right)
71 # - \frac{1}{2} \cdot \frac{A}{r_{\mathrm{cut}}} \cdot \left(r_{\mathrm{cut}}^2 - r^2 \right)
72 # & r < r_{\mathrm{cut}} \\
73 # = & 0 & r \ge r_{\mathrm{cut}} \\
74 # \f}
76 # Coeffients:
77 # - \f$ k \f$ - %force constant (in units of energy/distance^2)
78 # - \f$ r_0 \f$ - %bond rest length (in distance units)
79 # - \f$ A \f$ - \a A (in force units)
80 # - \f$ r_{\mathrm{cut}} \f$ - \c r_cut (in distance units)
82 # Coefficients \f$ k \f$, \f$ r_0 \f$, \f$ A \f$ and \f$ r_{\mathrm{cut}} \f$
83 # must be set for each type of %bond in the simulation using
84 # set_coeff().
86 # \note Specifying the bond.harmonic_dpd command when no bonds are defined in the simulation results in an error.
87 class harmonic_dpd(_bond):
88 ## Specify the %harmonic_dpd %bond %force
90 # \param name Name of the bond instance
92 # \b Example:
93 # \code
94 # harmonic_dpd = bond.harmonic_dpd(name="mybond")
95 # \endcode
96 def __init__(self,name=None):
97 util.print_status_line();
99 # check that some bonds are defined
100 if globals.system_definition.getBondData().getNumBonds() == 0:
101 print >> sys.stderr, "\n***Error! No bonds are defined.\n";
102 raise RuntimeError("Error creating bond forces");
104 # initialize the base class
105 _bond.__init__(self,name);
107 # create the c++ mirror class
108 if not globals.exec_conf.isCUDAEnabled():
109 self.cpp_force = _evaluators_ext_template.PotentialBondHarmonicDPD(globals.system_definition,self.name);
110 else:
111 self.cpp_force = _evaluators_ext_template.PotentialBondHarmonicDPDGPU(globals.system_definition,self.name);
112 # you can play with the block size value, set it to any multiple of 32 up to 1024. Use the
113 # harmonic_dpd.benchmark() command to find out which block size performs the fastest
114 self.cpp_force.setBlockSize(64);
116 globals.system.addCompute(self.cpp_force, self.force_name);
118 self.required_coeffs = ['k','r0','r_cut', 'A'];
120 def process_coeff(self, coeff):
121 k = coeff['k'];
122 r0 = coeff['r0'];
123 A = coeff['A'];
124 r_cut = coeff['r_cut'];
126 return hoomd.make_scalar4(k, r0, r_cut, A);