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 # Maintainer: joaander / All Developers are free to add commands for new features
52 from hoomd_script
import force
;
53 from hoomd_script
import globals;
55 from hoomd_script
import util
;
56 from hoomd_script
import tune
;
61 ## \package hoomd_script.improper
62 # \brief Commands that specify %improper forces
64 # Impropers add forces between specified quadruplets of particles and are typically used to
65 # model rotation about chemical bonds without having bonds to connect the atoms. Their most
66 # common use is to keep structural elements flat, i.e. model the effect of conjugated
67 # double bonds, like in benzene rings and its derivatives.
68 # Impropers between particles are set when an input XML file is read
69 # (init.read_xml) or when an another initializer creates them (like init.create_random_polymers)
71 # By themselves, impropers that have been specified in an input file do nothing. Only when you
72 # specify an improper force (i.e. improper.harmonic), are forces actually calculated between the
75 ## Harmonic %improper force
77 # The command improper.harmonic specifies a %harmonic improper potential energy between every quadruplet of particles
79 # \f[ V(r) = \frac{1}{2}k \left( \chi - \chi_{0} \right )^2 \f]
80 # where \f$ \chi \f$ is angle between two sides of the improper
83 # - \f$ k \f$ - strength of %force (in energy units)
84 # - \f$ \chi_{0} \f$ - equilibrium angle (in radians)
86 # Coefficients \f$ k \f$ and \f$ \chi_0 \f$ must be set for each type of %improper in the simulation using
89 # \note Specifying the improper.harmonic command when no impropers are defined in the simulation results in an error.
92 class harmonic(force
._force
):
93 ## Specify the %harmonic %improper %force
97 # harmonic = improper.harmonic()
100 util
.print_status_line();
101 # check that some impropers are defined
102 if globals.system_definition
.getImproperData().getNGlobal() == 0:
103 globals.msg
.error("No impropers are defined.\n");
104 raise RuntimeError("Error creating improper forces");
106 # initialize the base class
107 force
._force
.__init
__(self
);
109 # create the c++ mirror class
110 if not globals.exec_conf
.isCUDAEnabled():
111 self
.cpp_force
= hoomd
.HarmonicImproperForceCompute(globals.system_definition
);
113 self
.cpp_force
= hoomd
.HarmonicImproperForceComputeGPU(globals.system_definition
);
115 globals.system
.addCompute(self
.cpp_force
, self
.force_name
);
117 # variable for tracking which improper type coefficients have been set
118 self
.improper_types_set
= [];
120 ## Sets the %harmonic %improper coefficients for a particular %improper type
122 # \param improper_type Improper type to set coefficients for
123 # \param k Coefficient \f$ k \f$ in the %force
124 # \param chi Coefficient \f$ \chi \f$ in the %force
126 # Using set_coeff() requires that the specified %improper %force has been saved in a variable. i.e.
128 # harmonic = improper.harmonic()
133 # harmonic.set_coeff('heme-ang', k=30.0, chi=1.57)
134 # harmonic.set_coeff('hdyro-bond', k=20.0, chi=1.57)
137 # The coefficients for every %improper type in the simulation must be set
138 # before the run() can be started.
139 def set_coeff(self
, improper_type
, k
, chi
):
140 util
.print_status_line();
142 # set the parameters for the appropriate type
143 self
.cpp_force
.setParams(globals.system_definition
.getImproperData().getTypeByName(improper_type
), k
, chi
);
145 # track which particle types we have set
146 if not improper_type
in self
.improper_types_set
:
147 self
.improper_types_set
.append(improper_type
);
149 def update_coeffs(self
):
150 # get a list of all improper types in the simulation
151 ntypes
= globals.system_definition
.getImproperData().getNTypes();
153 for i
in range(0,ntypes
):
154 type_list
.append(globals.system_definition
.getImproperData().getNameByType(i
));
156 # check to see if all particle types have been set
157 for cur_type
in type_list
:
158 if not cur_type
in self
.improper_types_set
:
159 globals.msg
.error(str(cur_type
) + " coefficients missing in improper.harmonic\n");
160 raise RuntimeError("Error updating coefficients");