Esempio n. 1
0
 def run(self, formula, system, filename):
     """Calculate energy of specified system and save to file."""
     system.get_potential_energy()
      # Won't create .bak file:
     traj = PickleTrajectory(open(filename, 'w'), 'w')
     traj.write(system)
     traj.close()
Esempio n. 2
0
    def run(self, formula, system, filename):
        """Calculate bond length of a dimer.

        This will calculate total energies for varying atomic
        separations close to the g2 bond length, allowing
        determination of bond length by fitting.
        """
        if len(system) != 2:
            raise ValueError('Not a dimer')
        traj = PickleTrajectory(open(filename, 'w'), 'w')
        pos = system.positions
        d = np.linalg.norm(pos[1] - pos[0])
        for x in range(-2, 3):
            system.set_distance(0, 1, d * (1.0 + x * 0.02))
            traj.write(system)
        traj.close()
Esempio n. 3
0
 def retrieve(self, formula, filename):
     traj = PickleTrajectory(filename, 'r')
     distances = np.array(
         [np.linalg.norm(a.positions[1] - a.positions[0]) for a in traj])
     energies = np.array([a.get_potential_energy() for a in traj])
     polynomial = np.polyfit(distances, energies, 2)  # or maybe 3rd order?
     # With 3rd order it is not always obvious which root is right
     pderiv = np.polyder(polynomial, 1)
     d0 = np.roots(pderiv)
     e0 = np.polyval(energies, d0)
     return distances, energies, d0, e0, polynomial
Esempio n. 4
0
    def read(self, filename, filetype=None):
        """Read from a file"""

        ftfe = filetype_from_ending(filename)
        aft = ase_filetype(filename)

        if ftfe == 'vmol':
            self.read_viewmol(filename)
        elif aft == 'traj':
            PickleTrajectory.__init__(self, filename)
        elif aft == 'gpaw-text':
            # this is strange code, but I don't know how to create the full
            # slice XXXXX
            last = read_gpaw_text(filename)
            self.__init__(atoms=last)
            s = slice(-1)
            rest = read_gpaw_text(filename, s)
            rest.append(last)
            self.append(rest)
        else:
            raise NotImplementedError('unknown file type "' + aft + '"')
Esempio n. 5
0
    def read(self, filename, filetype=None):
        """Read from a file"""

        ftfe = filetype_from_ending(filename)
        aft = ase_filetype(filename)
        
        if ftfe == 'vmol':
            self.read_viewmol(filename)
        elif aft == 'traj':
            PickleTrajectory.__init__(self, filename)
        elif aft == 'gpaw-text':
            # this is strange code, but I don't know how to create the full
            # slice XXXXX
            last = read_gpaw_text(filename)
            self.__init__(atoms=last)
            s = slice(-1)
            rest = read_gpaw_text(filename, s)
            rest.append(last)
            self.append(rest)
        else:
            raise NotImplementedError('unknown file type "'+ aft +'"')
Esempio n. 6
0
 def run(self, formula, system, filename):
     """Calculate energy of specified system and save to file."""
     system.get_potential_energy()
     # Won't create .bak file:
     traj = PickleTrajectory(open(filename, 'w'), 'w')
     traj.write(system)
     traj.close()
Esempio n. 7
0
    def run(self, formula, system, filename):
        """Calculate bond length of a dimer.

        This will calculate total energies for varying atomic
        separations close to the g2 bond length, allowing
        determination of bond length by fitting.
        """
        if len(system) != 2:
            raise ValueError('Not a dimer')
        traj = PickleTrajectory(open(filename, 'w'), 'w')
        pos = system.positions
        d = np.linalg.norm(pos[1] - pos[0])
        for x in range(-2, 3):
            system.set_distance(0, 1, d * (1.0 + x * 0.02))
            traj.write(system)
        traj.close()
Esempio n. 8
0
 def __iter__(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.__iter__(self)
     else:
         return self.images.__iter__()
Esempio n. 9
0
 def __getitem__(self, i=-1):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.__getitem__(self, i)
     else:
         return self.images[i]
Esempio n. 10
0
 def __len__(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.__len__(self)
     else:
         return len(self.images)
Esempio n. 11
0
 def next(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.next(self)
     else:
         return self.images.next()
Esempio n. 12
0
 def __iter__(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.__iter__(self)
     else:
         return self.images.__iter__()
Esempio n. 13
0
 def __getitem__(self, i=-1):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.__getitem__(self, i)
     else:
         return self.images[i]
Esempio n. 14
0
 def __len__(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.__len__(self)
     else:
         return len(self.images)
Esempio n. 15
0
 def next(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.next(self)
     else:
         return self.images.next()
Esempio n. 16
0
import os
import sys

from ase import Atoms, Atom, QuasiNewton, PickleTrajectory

from gpaw import *
from gpaw.cluster import Cluster
from gpaw.utilities.viewmol import ViewmolTrajectory, write_viewmol

s = Cluster([Atom('H'), Atom('H', (0, 0, 3))])
s.minimal_box(2)
c = GPAW(h=0.3, nbands=2)
s.set_calculator(c)

vfname = 'traj.vmol'
pfname = 'traj.pickle'
vmt = ViewmolTrajectory(s, vfname)
traj = PickleTrajectory(pfname, 'w', s)
#c.attach(vmt.add, 100000)
#sys.exit()

# Find the theoretical bond length:
dyn = QuasiNewton(s)
dyn.attach(traj.write)
dyn.attach(vmt.add)
dyn.run(fmax=0.05)

traj = PickleTrajectory(pfname, 'r')
vfname2 = 'pickle.vmol'
write_viewmol(traj, vfname2)
Esempio n. 17
0
 def __next__(self):
     if hasattr(self, 'offsets'):
         return PickleTrajectory.next(self)
     else:
         return next(self.images)