class InputAtomSwap(InputDictionary): """Alchemy input class. Handles generating the appropriate alchemical exchange class from the xml input file. Fields: spicesA/B: isotopes for exchanges. timestep: An optional float giving the size of the timestep in atomic units. Defaults to 1.0. """ attribs = {"mode": (InputAttribute, {"dtype": str, "default": 'dummy', "help": " ", "options": ['dummy']})} fields = { "names": (InputArray, {"dtype": str, "default": input_default(factory=np.zeros, args=(0,), kwargs={'dtype': np.dtype('|S6')}), "help": "The names of the atoms to be to exchanged, in the format [name1, name2, ... ]."}), "nxc": (InputValue, {"dtype": float, "default": 1, "help": "The average number of exchanges per step to be attempted "}), "ealc": (InputValue, {"dtype": float, "default": 0.0, "help": "The contribution to the conserved quantity for the atom swapper"}) } dynamic = {} default_help = "Holds all the information for doing Monte Carlo atom swap moves. " default_label = "ATOMSWAP" def store(self, alc): """Takes an alchemical exchange instance and stores a minimal representation of it. Args: alc: An alchemy object. """ if alc == {}: return self.names.store(alc.names) self.nxc.store(alc.nxc) self.ealc.store(alc.ealc) def fetch(self): """Creates an ensemble object. Returns: An ensemble object of the appropriate mode and with the appropriate objects given the attributes of the InputEnsemble object. """ rv = super(InputAtomSwap, self).fetch() rv["mode"] = self.mode.fetch() return rv
class InputAtomSwap(InputDictionary): """Atomswap input class. Monte Carlo swaps of atoms types Fields: names: labels of the atoms that should be exchanged. nxc: how many swaps should be attempted at each step. defaults to 1.0. """ attribs = { "mode": ( InputAttribute, { "dtype": str, "default": "dummy", "help": " ", "options": ["dummy"] }, ) } fields = { "names": ( InputArray, { "dtype": str, "default": input_default(factory=np.zeros, args=(0, ), kwargs={"dtype": np.dtype("|U6")}), "help": "The names of the atoms to be to exchanged, in the format [name1, name2, ... ].", }, ), "nxc": ( InputValue, { "dtype": float, "default": 1, "help": "The average number of exchanges per step to be attempted ", }, ), "ealc": ( InputValue, { "dtype": float, "default": 0.0, "help": "The contribution to the conserved quantity for the atom swapper", }, ), } dynamic = {} default_help = "Holds all the information for doing Monte Carlo atom swap moves. " default_label = "ATOMSWAP" def store(self, alc): """Takes an alchemical exchange instance and stores a minimal representation of it. Args: alc: An alchemy object. """ if alc == {}: return self.names.store(alc.names) self.nxc.store(alc.nxc) self.ealc.store(alc.ealc) def fetch(self): """Creates an ensemble object. Returns: An ensemble object of the appropriate mode and with the appropriate objects given the attributes of the InputEnsemble object. """ rv = super(InputAtomSwap, self).fetch() rv["mode"] = self.mode.fetch() return rv
class InputPlanetary(InputDictionary): """Planetary input class. Handles generating the appropriate ensemble class from the xml input file, and generating the xml checkpoint tags and data from an instance of the object. Attributes: mode: An optional string giving the mode (ensemble) to be simulated. Defaults to 'unknown'. Fields: thermostat: The thermostat to be used for constant temperature dynamics. barostat: The barostat to be used for constant pressure or stress dynamics. timestep: An optional float giving the size of the timestep in atomic units. Defaults to 1.0. """ attribs = { "mode": (InputAttribute, {"dtype": str, "default": 'md', "help": "The constrained-centroid sampling mode. ", "options": ['md']}) } fields = { "thermostat": (InputThermo, {"default": input_default(factory=ipi.engine.thermostats.Thermostat), "help": "The thermostat for the atoms, keeps the atom velocity distribution at the correct temperature."}), "timestep": (InputValue, {"dtype": float, "default": 1.0, "help": "The time step.", "dimension": "time"}), "nmts": (InputArray, {"dtype": int, "default": np.zeros(0, int), "help": "Number of iterations for each MTS level (including the outer loop, that should in most cases have just one iteration)."}), "nsamples": (InputValue, {"dtype": int, "default": 0, "help": "Number of samples to accumulate for each planetary step."}), "stride": (InputValue, {"dtype": int, "default": 1, "help": "How often the planetary calculation should actually be triggered."}), "nbeads": (InputValue, {"dtype": int, "default": -1, "help": "Number of beads for centroid-constrained dynamics (default same as master trajectory)"}), "screen": (InputValue, {"dtype": float, "default": 0.0, "dimension": "length", "help": "Screening parameter for path-integral frequency matrix."}) } dynamic = {} default_help = "Holds all the information for the planetary model frequency matrix calculator." default_label = "PLANETARY" def store(self, plan): """Takes a planetary instance and stores a minimal representation of it. Args: dyn: An integrator object. """ if plan == {}: return self.mode.store(plan.mode) self.timestep.store(plan.ccdyn.dt) self.thermostat.store(plan.ccdyn.thermostat) self.nmts.store(plan.ccdyn.nmts) self.nsamples.store(plan.nsamples) self.stride.store(plan.stride) self.screen.store(plan.screen) def fetch(self): """Creates an ensemble object. Returns: An ensemble object of the appropriate mode and with the appropriate objects given the attributes of the InputEnsemble object. """ rv = super(InputPlanetary, self).fetch() rv["mode"] = self.mode.fetch() return rv
class InputConstrainedDynamics(InputDictionary): """Dynamics input class. Handles generating the appropriate ensemble class from the xml input file, and generating the xml checkpoint tags and data from an instance of the object. Attributes: mode: An optional string giving the mode (ensemble) to be simulated. Defaults to 'unknown'. Fields: thermostat: The thermostat to be used for constant temperature dynamics. barostat: The barostat to be used for constant pressure or stress dynamics. timestep: An optional float giving the size of the timestep in atomic units. Defaults to 1.0. """ attribs = { "mode": ( InputAttribute, { "dtype": str, "default": "nve", "help": "The ensemble that will be sampled during the simulation. ", "options": ["nve", "nvt"], }, ), "splitting": ( InputAttribute, { "dtype": str, "default": "baoab", "help": "The integrator used for sampling the target ensemble. ", "options": ["obabo", "baoab"], }, ), } fields = { "thermostat": ( InputThermo, { "default": input_default(factory=ipi.engine.thermostats.Thermostat), "help": "The thermostat for the atoms, keeps the atom velocity distribution at the correct temperature.", }, ), "barostat": ( InputBaro, { "default": input_default(factory=ipi.engine.barostats.Barostat), "help": InputBaro.default_help, }, ), "timestep": ( InputValue, { "dtype": float, "default": 1.0, "help": "The time step.", "dimension": "time", }, ), "nmts": ( InputArray, { "dtype": int, "default": np.zeros(0, int), "help": "Number of iterations for each MTS level (including the outer loop, that should in most cases have just one iteration).", }, ), "nsteps_o": ( InputValue, { "dtype": int, "default": 1, "help": "The number of sub steps used in the evolution of the thermostat (used in function step_Oc). Relevant only for GLE thermostats", }, ), "nsteps_geo": ( InputValue, { "dtype": int, "default": 1, "help": "The number of sub steps used in the evolution of the geodesic flow (used in function step_Ag).", }, ), "csolver": ( InputConstraintSolver, { "help": "Define a numerical method for computing the projection operators associated with the constraint." }, ), } dynamic = { "constraint": ( InputConstraint, { "help": "Define a constraint to be applied onto atoms" }, ) } default_help = "Holds all the information for the MD integrator, such as timestep, the thermostats and barostats that control it." default_label = "CONSTRAINEDDYNAMICS" def store(self, dyn): """Takes an ensemble instance and stores a minimal representation of it. Args: dyn: An integrator object. """ if dyn == {}: return self.mode.store(dyn.enstype) self.timestep.store(dyn.dt) self.thermostat.store(dyn.thermostat) self.barostat.store(dyn.barostat) self.nmts.store(dyn.nmts) self.splitting.store(dyn.splitting) self.nsteps_o.store(dyn.nsteps_o) self.nsteps_geo.store(dyn.nsteps_geo) self.csolver.store(dyn.csolver) self.extra = [] for constr in dyn.constraint_list: iobj = InputConstraint() iobj.store(constr) self.extra.append(("constraint", iobj)) def fetch(self): """Creates a ConstrainedDynamics object. Returns: An ensemble object of the appropriate mode and with the appropriate objects given the attributes of the InputEnsemble object. """ rv = super(InputConstrainedDynamics, self).fetch() rv["mode"] = self.mode.fetch() rv["splitting"] = self.splitting.fetch() rv["csolver"] = self.csolver.fetch() cnstr_list = [] for (k, v) in self.extra: if k == "constraint": cnstr_list.append(v.fetch()) else: raise ValueError("Invalid entry " + k + " in constrained_dynamics") rv["constraint_list"] = cnstr_list return rv
class InputDynamics(InputDictionary): """Dynamics input class. Handles generating the appropriate ensemble class from the xml input file, and generating the xml checkpoint tags and data from an instance of the object. Attributes: mode: An optional string giving the mode (ensemble) to be simulated. Defaults to 'unknown'. Fields: thermostat: The thermostat to be used for constant temperature dynamics. barostat: The barostat to be used for constant pressure or stress dynamics. timestep: An optional float giving the size of the timestep in atomic units. Defaults to 1.0. """ attribs = { "mode": (InputAttribute, { "dtype": str, "default": 'nve', "help": "The ensemble that will be sampled during the simulation. ", "options": ['nve', 'nvt', 'npt', 'nst', 'sc', 'scnpt'] }), "splitting": (InputAttribute, { "dtype": str, "default": 'obabo', "help": "The Louiville splitting used for sampling the target ensemble. ", "options": ['obabo', 'baoab'] }) } fields = { "thermostat": (InputThermo, { "default": input_default(factory=ipi.engine.thermostats.Thermostat), "help": "The thermostat for the atoms, keeps the atom velocity distribution at the correct temperature." }), "barostat": (InputBaro, { "default": input_default(factory=ipi.engine.barostats.Barostat), "help": InputBaro.default_help }), "timestep": (InputValue, { "dtype": float, "default": 1.0, "help": "The time step.", "dimension": "time" }), "nmts": (InputArray, { "dtype": int, "default": np.zeros(0, int), "help": "Number of iterations for each MTS level (including the outer loop, that should in most cases have just one iteration)." }) } dynamic = {} default_help = "Holds all the information for the MD integrator, such as timestep, the thermostats and barostats that control it." default_label = "DYNAMICS" def store(self, dyn): """Takes an ensemble instance and stores a minimal representation of it. Args: dyn: An integrator object. """ if dyn == {}: return self.mode.store(dyn.enstype) self.timestep.store(dyn.dt) self.thermostat.store(dyn.thermostat) self.barostat.store(dyn.barostat) self.nmts.store(dyn.nmts) self.splitting.store(dyn.splitting) def fetch(self): """Creates an ensemble object. Returns: An ensemble object of the appropriate mode and with the appropriate objects given the attributes of the InputEnsemble object. """ rv = super(InputDynamics, self).fetch() rv["mode"] = self.mode.fetch() rv["splitting"] = self.splitting.fetch() return rv