Пример #1
0
    def __init__(self, atoms,
                 temperature=100 * kB,
                 optimizer=FIRE,
                 fmax=0.1,
                 dr=.1,
                 logfile='-', 
                 trajectory='lowest.traj',
                 optimizer_logfile='-',
                 local_minima_trajectory='local_minima.traj',
                 adjust_cm=True):
        Dynamics.__init__(self, atoms, logfile, trajectory)
        self.kT = temperature
        self.optimizer = optimizer
        self.fmax = fmax
        self.dr = dr
        if adjust_cm:
            self.cm = atoms.get_center_of_mass()
        else:
            self.cm = None

        self.optimizer_logfile = optimizer_logfile
        self.lm_trajectory = local_minima_trajectory
        if isinstance(local_minima_trajectory, str):
            self.lm_trajectory = PickleTrajectory(local_minima_trajectory,
                                                  'w', atoms)

        self.initialize()
Пример #2
0
 def write_mode(self, n, kT=units.kB * 300, nimages=30):
     """Write mode to trajectory file."""
     mode = self.get_mode(n) * sqrt(kT / abs(self.hnu[n]))
     p = self.atoms.positions.copy()
     n %= 3 * len(self.indices)
     traj = PickleTrajectory('%s.%d.traj' % (self.name, n), 'w')
     calc = self.atoms.get_calculator()
     self.atoms.set_calculator()
     for x in np.linspace(0, 2 * pi, nimages, endpoint=False):
         self.atoms.set_positions(p + sin(x) * mode)
         traj.write(self.atoms)
     self.atoms.set_positions(p)
     self.atoms.set_calculator(calc)
     traj.close()
Пример #3
0
 def replay_trajectory(self, traj):
     """Initialize hessian from old trajectory."""
     self.replay = True
     if isinstance(traj, str):
         from ase_ext.io.trajectory import PickleTrajectory
         traj = PickleTrajectory(traj, 'r')
     atoms = traj[0]
     r0 = None
     g0 = None
     for i in range(0, len(traj) - 1):
         r = traj[i].get_positions().ravel()
         g = -traj[i].get_forces().ravel() / self.alpha
         self.update(r, g, r0, g0, self.p)
         self.p = -np.dot(self.H, g)
         r0 = r.copy()
         g0 = g.copy()
     self.r0 = r0
     self.g0 = g0
Пример #4
0
 def replay_trajectory(self, traj):
     """Initialize history from old trajectory."""
     if isinstance(traj, str):
         from ase_ext.io.trajectory import PickleTrajectory
         traj = PickleTrajectory(traj, 'r')
     r0 = None
     f0 = None
     # The last element is not added, as we get that for free when taking
     # the first qn-step after the replay
     for i in range(0, len(traj) - 1):
         r = traj[i].get_positions()
         f = traj[i].get_forces()
         self.update(r, f, r0, f0)
         r0 = r.copy()
         f0 = f.copy()
         self.iteration += 1
     self.r0 = r0
     self.f0 = f0
Пример #5
0
    def replay_trajectory(self, traj):
        """Initialize hessian from old trajectory."""
        if isinstance(traj, str):
            from ase_ext.io.trajectory import PickleTrajectory
            traj = PickleTrajectory(traj, 'r')
        self.H = None
        atoms = traj[0]
        r0 = atoms.get_positions().ravel()
        f0 = atoms.get_forces().ravel()
        for atoms in traj:
            r = atoms.get_positions().ravel()
            f = atoms.get_forces().ravel()
            self.update(r, f, r0, f0)
            r0 = r
            f0 = f

        self.r0 = r0
        self.f0 = f0
Пример #6
0
    def __init__(self, atoms, logfile, trajectory):
        self.atoms = atoms

        if rank != 0:
            logfile = None
        elif isinstance(logfile, str):
            if logfile == '-':
                logfile = sys.stdout
            else:
                logfile = open(logfile, 'a')
        self.logfile = logfile

        self.observers = []
        self.nsteps = 0

        if trajectory is not None:
            if isinstance(trajectory, str):
                trajectory = PickleTrajectory(trajectory, 'w', atoms)
            self.attach(trajectory)
Пример #7
0
 def write(self, filename):
     from ase_ext.io.trajectory import PickleTrajectory
     traj = PickleTrajectory(filename, 'w', self)
     traj.write()
     traj.close()