1 """Deals with creating the beads 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/>.
20 InputBeads: Deals with creating the Beads object from a file, and
21 writing the checkpoints.
25 from ipi
.engine
.beads
import *
26 from ipi
.engine
.atoms
import Atoms
27 from ipi
.utils
.inputvalue
import *
28 from ipi
.utils
.depend
import *
29 from ipi
.utils
.units
import *
30 from ipi
.inputs
.atoms
import *
32 __all__
= ['InputBeads']
34 class InputBeads(Input
):
37 Handles generating the appropriate beads class from the xml input file,
38 and generating the xml checkpoint tags and data from an instance of the
42 nbeads: An optional integer giving the number of beads. Defaults to 0.
43 natoms: An optional integer giving the number of atoms. Defaults to 0.
46 q: An optional array giving the bead positions. Defaults to an empty
47 array with no elements.
48 p: An optional array giving the bead momenta. Defaults to an empty
49 array with no elements.
50 m: An optional array giving the bead masses. Defaults to an empty array
52 names: An optional array giving the bead names. Defaults to an empty
53 array with no elements.
56 attribs
= { "natoms" : (InputAttribute
, {"dtype" : int, "default" : 0,
57 "help" : "The number of atoms."}),
58 "nbeads" : (InputAttribute
, {"dtype" : int, "default" : 0,
59 "help" : "The number of beads."})
61 fields
={ "q" : (InputArray
, {"dtype" : float,
62 "default" : input_default(factory
=np
.zeros
, args
= (0,)),
63 "help" : "The positions of the beads. In an array of size [nbeads, 3*natoms].",
64 "dimension" : "length"}),
65 "p" : (InputArray
, {"dtype" : float,
66 "default" : input_default(factory
=np
.zeros
, args
= (0,)),
67 "help" : "The momenta of the beads. In an array of size [nbeads, 3*natoms].",
68 "dimension" : "momentum"}),
69 "m" : (InputArray
, {"dtype" : float,
70 "default" : input_default(factory
=np
.zeros
, args
= (0,)),
71 "help" : "The masses of the atoms, in the format [m1, m2, ... ].",
72 "dimension" : "mass"}),
73 "names" : (InputArray
, {"dtype" : str,
74 "default" : input_default(factory
=np
.zeros
, args
=(0,), kwargs
={'dtype': np
.dtype('|S6')}),
75 "help" : "The names of the atoms, in the format [name1, name2, ... ]."}) }
77 default_help
= "Describes the bead configurations in a path integral simulation."
78 default_label
= "BEADS"
81 def store(self
, beads
):
82 """Takes a Beads instance and stores a minimal representation of it.
85 beads: A Beads object from which to initialise from.
88 super(InputBeads
,self
).store()
89 self
.natoms
.store(beads
.natoms
)
90 self
.nbeads
.store(beads
.nbeads
)
92 self
.q
.store(depstrip(beads
.q
))
93 self
.p
.store(depstrip(beads
.p
))
94 self
.m
.store(depstrip(beads
.m
))
95 self
.names
.store(depstrip(beads
.names
))
98 """Creates a beads object.
101 A beads object of the appropriate type and with the appropriate
102 properties given the attributes of the InputBeads object.
105 super(InputBeads
,self
).fetch()
106 beads
= Beads(self
.natoms
.fetch(),self
.nbeads
.fetch())
108 # tries to fill up with as much data as available and valid
110 if (q
.shape
== (beads
.nbeads
,3*beads
.natoms
)):
112 elif (beads
.nbeads
== 1 and q
.shape
== (3*beads
.natoms
,)):
115 raise ValueError("Array shape mismatches for q in <beads> input.")
118 if (p
.shape
== (beads
.nbeads
,3*beads
.natoms
)):
120 elif (beads
.nbeads
== 1 and p
.shape
== (3*beads
.natoms
,)):
123 raise ValueError("Array shape mismatches for p in <beads> input.")
126 if (m
.shape
== (beads
.natoms
,)):
129 raise ValueError("Array shape mismatches for m in <beads> input.")
131 n
= self
.names
.fetch()
132 if (n
.shape
== (beads
.natoms
,)):
135 raise ValueError("Array shape mismatches for names in <beads> input.")