Exemplo n.º 1
0
    def fetch(self):
        """Creates a motion calculator object.

        Returns:
           An ensemble object of the appropriate mode and with the appropriate
           objects given the attributes of the InputEnsemble object.
        """

        super(InputMotionBase, self).fetch()

        if self.mode.fetch() == "replay":
            sc = Replay(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), intraj=self.file.fetch())
        elif self.mode.fetch() == "minimize":
            sc = GeopMotion(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), **self.optimizer.fetch())
        elif self.mode.fetch() == "neb":
            sc = NEBMover(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), **self.neb_optimizer.fetch())
        elif self.mode.fetch() == "dynamics":
            sc = Dynamics(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), **self.dynamics.fetch())
        elif self.mode.fetch() == "vibrations":
            sc = DynMatrixMover(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), **self.vibrations.fetch())
        elif self.mode.fetch() == "alchemy":
            sc = AlchemyMC(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), **self.alchemy.fetch())
        elif self.mode.fetch() == "instanton":
            sc = InstantonMotion(fixcom=self.fixcom.fetch(), fixatoms=self.fixatoms.fetch(), **self.instanton.fetch())
        elif self.mode.fetch() == "t_ramp":
            sc = TemperatureRamp(**self.t_ramp.fetch())
        elif self.mode.fetch() == "p_ramp":
            sc = PressureRamp(**self.p_ramp.fetch())
        else:
            sc = Motion()
            # raise ValueError("'" + self.mode.fetch() + "' is not a supported motion calculation mode.")

        return sc
Exemplo n.º 2
0
    def __init__(self,
                 mode,
                 geop,
                 nstep,
                 a0,
                 ncell,
                 nvac,
                 nsi,
                 nmg,
                 neval,
                 diffusion_barrier_al,
                 diffusion_prefactor_al,
                 diffusion_barrier_mg,
                 diffusion_prefactor_mg,
                 diffusion_barrier_si,
                 diffusion_prefactor_si,
                 idx=[],
                 tottime=0,
                 ecache_file="",
                 qcache_file="",
                 thermostat=None,
                 barostat=None,
                 fixcom=False,
                 fixatoms=None,
                 nmts=None):
        """Initialises a "dynamics" motion object.

        Args:
            dt: The timestep of the simulation algorithms.
            fixcom: An optional boolean which decides whether the centre of mass
                motion will be constrained or not. Defaults to False.
        """

        # This will generate a lattice model based on a primitive FCC cell. the lattice is represented in three ways:
        # 1. as a string in which each lattice site is identified by a letter
        # 2. by a list of the lattice sites in 3D space, in 1-1 mapping with the letters
        # 3. by a list of the atoms, whose lattice position is indicated by an integer

        self.nstep = nstep
        self.ncell = ncell
        self.nvac = nvac
        self.nsi = nsi
        self.nmg = nmg
        self.nsites = self.ncell**3
        self.natoms = self.nsites - self.nvac
        self.neval = neval
        self.diffusion_barrier_al = diffusion_barrier_al
        self.diffusion_prefactor_al = diffusion_prefactor_al
        if diffusion_barrier_mg > 0:
            self.diffusion_barrier_mg = diffusion_barrier_mg
        else:
            self.diffusion_barrier_mg = diffusion_barrier_al
        if diffusion_barrier_si > 0:
            self.diffusion_barrier_si = diffusion_barrier_si
        else:
            self.diffusion_barrier_si = diffusion_barrier_al
        if diffusion_prefactor_mg > 0:
            self.diffusion_prefactor_mg = diffusion_prefactor_mg
        else:
            self.diffusion_prefactor_mg = diffusion_prefactor_al
        if diffusion_prefactor_si > 0:
            self.diffusion_prefactor_si = diffusion_prefactor_si
        else:
            self.diffusion_prefactor_si = diffusion_prefactor_al
        self.barriers = {
            "A": self.diffusion_barrier_al,
            "M": self.diffusion_barrier_mg,
            "S": self.diffusion_barrier_si
        }
        self.prefactors = {
            "A": self.diffusion_prefactor_al,
            "M": self.diffusion_prefactor_mg,
            "S": self.diffusion_prefactor_si
        }

        self.a0 = a0
        cell = np.zeros((3, 3))
        cell[0] = [
            0.7071067811865475, 0.35355339059327373, 0.35355339059327373
        ]
        cell[1] = [0., 0.6123724356957945, 0.20412414523193154]
        cell[2] = [0., 0., 0.5773502691896258]
        self.scell = self.a0 * cell
        self.dcell = Cell()
        self.dcell.h = self.scell * self.ncell

        print "LATTICE PARAM ", self.a0
        # this is the list of lattice sites, in 3D coordinates
        ix, iy, iz = np.meshgrid(range(self.ncell),
                                 range(self.ncell),
                                 range(self.ncell),
                                 indexing='ij')
        self.sites = np.dot(
            np.asarray([ix.flatten(), iy.flatten(),
                        iz.flatten()]).T, self.scell.T)
        print len(self.sites), self.nsites, "###"
        # now we build list of nearest neighbors (fcc-lattice hardcoded!)
        self.neigh = np.zeros((self.nsites, 12), int)
        nneigh = np.zeros(self.nsites, int)
        # could be done in a more analytic way but whatever, I'm too lazy
        a02 = 1.01 * 0.5 * self.a0**2  # perhaps 1.01 it is not enough, must check!
        for i in xrange(
                self.nsites):  # determines the connectivity of the lattice
            rij = self.sites.copy().flatten()
            for j in xrange(self.nsites):
                rij[3 * j:3 * j + 3] -= self.sites[i]
            self.dcell.array_pbc(rij)
            rij.shape = (self.nsites, 3)
            for j in xrange(i):
                if np.dot(rij[j], rij[j]) < a02:  # found nearest neighbor
                    self.neigh[i, nneigh[i]] = j
                    self.neigh[j, nneigh[j]] = i
                    nneigh[i] += 1
                    nneigh[j] += 1

        self.idx = idx

        # the KMC step is variable and so it cannot be stored as proper timing
        dd(self).dt = depend_value(name="dt", value=0.0)
        self.fixatoms = np.asarray([])
        self.fixcom = True
        self.geop = [None] * self.neval
        # geop should not trigger exit if there is early convergence, but just carry on.
        # we hard-code this option to avoid early-termination that would be hard to debug for a user
        geop["exit_on_convergence"] = False
        for i in xrange(self.neval):
            # geometry optimizer should not have *any* hystory dependence
            self.geop[i] = GeopMotion(
                fixcom=fixcom, fixatoms=fixatoms, **geop
            )  #mode="cg", ls_options={"tolerance": 1, "iter": 20,  "step": 1e-3, "adaptive": 0.0}, tolerances={"energy": 1e-7, "force": 1e-2, "position": 1e-4}, ) #!TODO: set the geop parameters properly

        # dictionary of previous energy evaluations - kind of tricky to use this with the omaker thingie
        self.ecache_file = ecache_file
        self.qcache_file = qcache_file
        try:
            ff = open(self.ecache_file, "rb")
            self.ecache = pickle.load(ff)
            ff.close()
            ff = open(self.qcache_file, "rb")
            self.qcache = pickle.load(ff)
            ff.close()
            print "Loaded %d cached energies" % (len(self.ecache))
        except:
            print "Couldn't load cache files " + self.ecache_file + "," + self.qcache_file + " - resetting"
            self.ecache = {}
            self.qcache = {}
        self.ncache = len(self.ecache)
        self.ncache_stored = self.ncache

        # no TS evaluation implemented yet
        self.tscache = {}
        self.tottime = tottime
Exemplo n.º 3
0
    def fetch(self):
        """Creates a motion calculator object.

        Returns:
           An ensemble object of the appropriate mode and with the appropriate
           objects given the attributes of the InputEnsemble object.
        """

        super(InputMotionBase, self).fetch()

        if self.mode.fetch() == "replay":
            sc = Replay(
                fixcom=self.fixcom.fetch(),
                fixatoms=self.fixatoms.fetch(),
                intraj=self.file.fetch(),
            )
        elif self.mode.fetch() == "minimize":
            sc = GeopMotion(fixcom=self.fixcom.fetch(),
                            fixatoms=self.fixatoms.fetch(),
                            **self.optimizer.fetch())
        elif self.mode.fetch() == "neb":

            raise ValueError(
                "The nudged elastic band calculation has been temporarily disabled until further bug-fixes."
            )
        #            sc = NEBMover(
        #                fixcom=self.fixcom.fetch(),
        #                fixatoms=self.fixatoms.fetch(),
        #                **self.neb_optimizer.fetch()
        #            )
        elif self.mode.fetch() == "dynamics":
            sc = Dynamics(fixcom=self.fixcom.fetch(),
                          fixatoms=self.fixatoms.fetch(),
                          **self.dynamics.fetch())
        elif self.mode.fetch() == "constrained_dynamics":
            sc = ConstrainedDynamics(fixcom=self.fixcom.fetch(),
                                     fixatoms=self.fixatoms.fetch(),
                                     **self.constrained_dynamics.fetch())
        elif self.mode.fetch() == "vibrations":
            sc = DynMatrixMover(fixcom=self.fixcom.fetch(),
                                fixatoms=self.fixatoms.fetch(),
                                **self.vibrations.fetch())
        elif self.mode.fetch() == "normalmodes":
            sc = NormalModeMover(fixcom=self.fixcom.fetch(),
                                 fixatoms=self.fixatoms.fetch(),
                                 **self.normalmodes.fetch())
        elif self.mode.fetch() == "scp":
            sc = SCPhononsMover(fixcom=self.fixcom.fetch(),
                                fixatoms=self.fixatoms.fetch(),
                                **self.scp.fetch())
        elif self.mode.fetch() == "alchemy":
            sc = AlchemyMC(fixcom=self.fixcom.fetch(),
                           fixatoms=self.fixatoms.fetch(),
                           **self.alchemy.fetch())
        elif self.mode.fetch() == "atomswap":
            sc = AtomSwap(fixcom=self.fixcom.fetch(),
                          fixatoms=self.fixatoms.fetch(),
                          **self.atomswap.fetch())
        elif self.mode.fetch() == "instanton":
            sc = InstantonMotion(fixcom=self.fixcom.fetch(),
                                 fixatoms=self.fixatoms.fetch(),
                                 **self.instanton.fetch())
        elif self.mode.fetch() == "planetary":
            sc = Planetary(fixcom=self.fixcom.fetch(),
                           fixatoms=self.fixatoms.fetch(),
                           **self.planetary.fetch())
        elif self.mode.fetch() == "t_ramp":
            sc = TemperatureRamp(**self.t_ramp.fetch())
        elif self.mode.fetch() == "p_ramp":
            sc = PressureRamp(**self.p_ramp.fetch())
        elif self.mode.fetch() == "al-kmc":
            sc = AlKMC(fixcom=self.fixcom.fetch(),
                       fixatoms=self.fixatoms.fetch(),
                       **self.al6xxx_kmc.fetch())
        else:
            sc = Motion()
            # raise ValueError("'" + self.mode.fetch() + "' is not a supported motion calculation mode.")

        return sc