git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@16053 f3b2605a-c512-4ea7-a41b...
[lammps.git] / tools / i-pi / ipi / inputs / barostats.py
blob84d0d83f43576388246755a295e1416e3159d32c
1 """Deals with creating the barostat class.
3 Copyright (C) 2013, Joshua More and Michele Ceriotti
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http.//www.gnu.org/licenses/>.
19 Classes:
20 InputBaro: Deals with creating the Barostat object from a file, and
21 writing the checkpoints.
22 """
24 import numpy as np
25 import ipi.engine.thermostats
26 from ipi.engine.barostats import *
27 from ipi.utils.inputvalue import *
28 from ipi.inputs.thermostats import *
30 __all__ = ['InputBaro']
32 class InputBaro(Input):
33 """Barostat input class.
35 Handles generating the appropriate barostat class from the xml input file,
36 and generating the xml checkpoint tags and data from an
37 instance of the object.
39 Attributes:
40 mode: An optional string giving the type of barostat used. Defaults to
41 'rigid'.
43 Fields:
44 thermostat: A thermostat object giving the cell thermostat.
45 tau: The time constant associated with the dynamics of the piston.
46 p: The conjugate momentum to the volume degree of freedom.
47 """
49 attribs={ "mode": (InputAttribute, {"dtype" : str,
50 "default" : "dummy",
51 "help" : """The type of barostat. Currently, only a 'isotropic' barostat is implemented, that combines
52 ideas from the Bussi-Zykova-Parrinello barostat for classical MD with ideas from the
53 Martyna-Hughes-Tuckerman centroid barostat for PIMD; see Ceriotti, More, Manolopoulos, Comp. Phys. Comm. 2013 for
54 implementation details.""",
55 "options" : ["dummy", "isotropic"]}) }
56 fields={ "thermostat": (InputThermo, {"default" : input_default(factory=ipi.engine.thermostats.Thermostat),
57 "help" : "The thermostat for the cell. Keeps the cell velocity distribution at the correct temperature. Note that the 'pile_l', 'pile_g', 'nm_gle' and 'nm_gle_g' options will not work for this thermostat."}),
58 "tau": (InputValue, {"default" : 1.0,
59 "dtype" : float,
60 "dimension" : "time",
61 "help" : "The time constant associated with the dynamics of the piston."}),
62 "p": (InputArray, { "dtype" : float,
63 "default" : input_default(factory=np.zeros, args = (0,)),
64 "help" : "Momentum (or momenta) of the piston.",
65 "dimension" : "momentum" })
68 default_help = "Simulates an external pressure bath."
69 default_label = "BAROSTAT"
71 def store(self, baro):
72 """Takes a barostat instance and stores a minimal representation of it.
74 Args:
75 baro: A barostat object.
76 """
78 super(InputBaro,self).store(baro)
79 self.thermostat.store(baro.thermostat)
80 self.tau.store(baro.tau)
81 if type(baro) is BaroBZP:
82 self.mode.store("isotropic")
83 self.p.store(baro.p)
84 elif type(baro) is Barostat:
85 self.mode.store("dummy")
86 else:
87 raise TypeError("The type " + type(baro).__name__ + " is not a valid barostat type")
90 def fetch(self):
91 """Creates a barostat object.
93 Returns:
94 A barostat object of the appropriate type and with the appropriate
95 thermostat given the attributes of the InputBaro object.
96 """
98 super(InputBaro,self).fetch()
99 if self.mode.fetch() == "isotropic":
100 baro = BaroBZP(thermostat=self.thermostat.fetch(), tau=self.tau.fetch())
101 if self.p._explicit: baro.p = self.p.fetch()
102 elif self.mode.fetch() == "dummy":
103 baro = Barostat(thermostat=self.thermostat.fetch(), tau=self.tau.fetch())
104 else:
105 raise ValueError(self.mode.fetch() + " is not a valid mode of barostat")
107 return baro