2 # Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 # (HOOMD-blue) Open Source Software License Copyright 2008-2011 Ames Laboratory
4 # Iowa State University and The Regents of the University of Michigan All rights
7 # HOOMD-blue may contain modifications ("Contributions") provided, and to which
8 # copyright is held, by various Contributors who have granted The Regents of the
9 # University of Michigan the right to modify and/or distribute such Contributions.
11 # You may redistribute, use, and create derivate works of HOOMD-blue, in source
12 # and binary forms, provided you abide by the following conditions:
14 # * Redistributions of source code must retain the above copyright notice, this
15 # list of conditions, and the following disclaimer both in the code and
16 # prominently in any materials provided with the distribution.
18 # * Redistributions in binary form must reproduce the above copyright notice, this
19 # list of conditions, and the following disclaimer in the documentation and/or
20 # other materials provided with the distribution.
22 # * All publications and presentations based on HOOMD-blue, including any reports
23 # or published results obtained, in whole or in part, with HOOMD-blue, will
24 # acknowledge its use according to the terms posted at the time of submission on:
25 # http://codeblue.umich.edu/hoomd-blue/citations.html
27 # * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
28 # http://codeblue.umich.edu/hoomd-blue/
30 # * Apart from the above required attributions, neither the name of the copyright
31 # holder nor the names of HOOMD-blue's contributors may be used to endorse or
32 # promote products derived from this software without specific prior written
37 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
38 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
39 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
40 # WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
42 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
43 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
47 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
48 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 # Maintainer: joaander / All Developers are free to add commands for new features
54 from hoomd_script
import globals;
56 from hoomd_script
import util
;
57 from hoomd_script
import init
;
59 ## \package hoomd_script.compute
60 # \brief Commands that %compute properties of the system
62 # A %compute calculates properties of the system on demand. Most computes are automatically generated by the command
63 # that needs them (e.g. integrate.nvt creates a compute.thermo for temperature calculations). User-specified computes
64 # can be used when more flexibility is needed. Properties calculated by specified computes (automatically, or by the
65 # user) can be logged with analyze.log.
68 # \brief Base class for computes
70 # A compute in hoomd_script reflects a Compute in c++. It is responsible
71 # for all high-level management that happens behind the scenes for hoomd_script
72 # writers. 1) The instance of the c++ compute itself is tracked and added to the
73 # System 2) methods are provided for disabling the compute
76 # \brief Constructs the compute
78 # Initializes the cpp_compute to None.
79 # Assigns a name to the compute in compute_name
81 # check if initialization has occurred
82 if not init
.is_initialized():
83 globals.msg
.error("Cannot create compute before initialization\n");
84 raise RuntimeError('Error creating compute');
86 self
.cpp_compute
= None;
88 # increment the id counter
92 self
.compute_name
= "compute%d" % (id);
97 # \brief True if the compute is enabled
101 # \brief Stores the C++ side Compute managed by this class
105 # \brief The Compute's name as it is assigned to the System
108 # \brief Checks that proper initialization has completed
109 def check_initialization(self
):
110 # check that we have been initialized properly
111 if self
.cpp_compute
is None:
112 globals.msg
.error('Bug in hoomd_script: cpp_compute not set, please report\n');
113 raise RuntimeError();
115 ## Disables the compute
122 # Executing the disable command will remove the %compute from the system. Any run() command executed after disabling
123 # a %compute will not be able to log computed values with analyze.log.
125 # A disabled %compute can be re-enabled with enable()
127 # To use this command, you must have saved the %compute in a variable, as
128 # shown in this example:
130 # c = compute.some_compute()
131 # # ... later in the script
135 util
.print_status_line();
136 self
.check_initialization();
138 # check if we are already disabled
140 globals.msg
.warning("Ignoring command to disable a compute that is already disabled");
143 globals.system
.removeCompute(self
.compute_name
);
144 self
.enabled
= False;
146 ## Enables the %compute
153 # See disable() for a detailed description.
155 util
.print_status_line();
156 self
.check_initialization();
158 # check if we are already disabled
160 globals.msg
.warning("Ignoring command to enable a compute that is already enabled");
163 globals.system
.addCompute(self
.cpp_compute
, self
.compute_name
);
166 # set default counter
170 ## Compute thermodynamic properties of a group of particles
172 # compute.thermo acts on a given group of particles and calculates thermodynamic properties of those particles when
173 # requested. A default compute.thermo is created that operates on the group of all particles. Integration methods
174 # such as integrate.nvt automatically create an internal compute.thermo for the group that they operate on.
175 # If thermodynamic properties are needed on additional groups, a user can specify additional compute.thermo commands.
177 # Whether they are automatically created or created by a user, all specified thermos are available for logging via
178 # the analyze.log command. Each one provides a set of quantities for logging, suffixed with _groupname, so that
179 # values for different groups are differentiated in the log file. The default compute.thermo specified on the group
180 # of all particles has no suffix placed on its quantity names.
182 # The quantities provided are:
183 # - <b>num_particles</b><i>_groupname</i> - \f$ N \f$ - number of particles in the group
184 # - <b>ndof</b><i>_groupname</i> - \f$ N_{\mathrm{dof}} \f$ - number of degrees of freedom given to the group by
186 # - <b>potential_energy</b><i>_groupname</i> - \f$ U \f$ - potential energy that the group contributes to the entire
187 # system (in energy units)
188 # - <b>kinetic_energy</b><i>_groupname</i> - \f$ K \f$ - total kinetic energy of all particles in the group (in energy units)
189 # - <b>temperature</b><i>_groupname</i> - \f$ T \f$ - instantaneous thermal energy of the group (in energy units). Calculated as
190 # \f$ T = 2 \cdot \frac{K}{N_{\mathrm{dof}}} \f$
191 # - <b>pressure</b><i>_groupname</i> - \f$ P \f$ - instantaneous pressure of the group (in pressure units). Calculated as
192 # \f$ P = (\frac{2}{3} \cdot K + \frac{1}{3}\cdot W)/V \f$ in 3D, where \f$ V \f$ is the volume of the simulation box and
193 # \f$ W = \frac{1}{2} \sum_{i}\sum_{j \ne i} \vec{F}_{ij} \cdot \vec{r_{ij}} \f$. In 2D simulations,
194 # \f$ P = (K + \frac{1}{2}\cdot W)/A \f$ where \f$ A \f$ is the area
195 # of the simulation box.
196 # - <b>pressure_xx</b><i>_groupname</i>, <b>pressure_xy</b><i>_groupname</i>, <b>pressure_xz</b><i>_groupname</i>,
197 # <b>pressure_yy</b><i>_groupname</i>, <b>pressure_yz</b><i>_groupname</i>, <b>pressure_zz</b><i>_groupname</i> -
198 # instantaneous pressure tensor of the group (in pressure units).
199 # \f[ P_{ij} = \left[ \sum_{k\in[0..N)} m_k v_{k,i} v_{k,j} +
200 # \sum_{k\in[0..N)} \sum_{l > k} \frac{1}{2} \left(\vec{r}_{kl,i} \vec{F}_{kl,j} + \vec{r}_{kl,j} \vec{F}_{kl, i} \right) \right]/V \f]
203 class thermo(_compute
):
204 ## Initialize the thermodynamics computation
206 # \param group Group for which to compute thermodynamic properties
210 # g = group.type(name='typeA', type='A')
211 # compute.thermo(group=g)
214 def __init__(self
, group
):
215 util
.print_status_line();
217 # initialize base class
218 _compute
.__init
__(self
);
221 if group
.name
!= 'all':
222 suffix
= '_' + group
.name
;
224 # warn user if an existing compute thermo already uses this group or name
225 for t
in globals.thermos
:
227 globals.msg
.warning("compute.thermo already specified for this group");
228 elif t
.group
.name
== group
.name
:
229 globals.msg
.warning("compute.thermo already specified for a group with name " + str(group
.name
) + "\n");
231 # create the c++ mirror class
232 if not globals.exec_conf
.isCUDAEnabled():
233 self
.cpp_compute
= hoomd
.ComputeThermo(globals.system_definition
, group
.cpp_group
, suffix
);
235 self
.cpp_compute
= hoomd
.ComputeThermoGPU(globals.system_definition
, group
.cpp_group
, suffix
);
237 globals.system
.addCompute(self
.cpp_compute
, self
.compute_name
);
239 # save the group for later referencing
241 # add ourselves to the list of compute thermos specified so far
242 globals.thermos
.append(self
);
245 # \brief Returns the previously created compute.thermo with the same group, if created. Otherwise, creates a new
247 def _get_unique_thermo(group
):
249 # first check the globals for an existing compute.thermo
250 for t
in globals.thermos
:
251 # if we find a match, return it
255 # if we get here, there were no matches: create a new one
256 util
._disable
_status
_lines
= True;
258 util
._disable
_status
_lines
= False;