Пример #1
0
    def read_run(self, taskname, tag, run):
        if tag is not None:
            tag += '_%s' % run
        else:
            tag = run

        return read_json(taskname + '-' + tag + '.json')
Пример #2
0
    def analyse(self, atomsfile=None):
        BulkTask.analyse(self)

        for name, data in self.data.items():
            if 'strains' in data:
                atoms = self.create_system(name)
                volume = atoms.get_volume()
                data['volume error [%]'] = (data['volume'] / volume - 1) * 100
                if self.collection.xc == 'PBE':
                    B = self.collection.data[name][-1] * units.kJ * 1e-24
                    data['B error [%]'] = (data['B'] / B - 1) * 100

        if atomsfile:
            atomdata = read_json(atomsfile)
            for name, data in self.data.items():
                atoms = self.create_system(name)
                e = -data['energy']
                for atom in atoms:
                    e += atomdata[atom.symbol]['energy']
                e /= len(atoms)
                data['cohesive energy'] = e
                if self.collection.xc == 'PBE':
                    eref = self.collection.data[name][7]
                else:
                    eref = self.collection.data[name][9]
                data['cohesive energy error [%]'] = (e / eref - 1) * 100

            self.summary_keys += ['cohesive energy',
                                  'cohesive energy error [%]']
Пример #3
0
    def read_run(self, taskname, tag, run):
        if tag is not None:
            tag += '_%s' % run
        else:
            tag = run

        return read_json(taskname + '-' + tag + '.json')
Пример #4
0
 def write(self, name, data):
     filename = self.get_filename(ext='json')
     try:
         self.lock.acquire()
         if os.path.isfile(filename):
             alldata = read_json(filename)
         else:
             alldata = {}
         alldata[name] = data
         write_json(filename, alldata)
     finally:
         self.lock.release()
Пример #5
0
    def analyse(self, atomsfile=None):
        try:
            BulkTask.analyse(self)
        except ValueError:  # allow fit outside of range
            pass

        for name, data in self.data.items():
            if 'strains' in data:
                atoms = self.create_system(name)
                # full equation of state
                # use relaxed volume if present
                if 'relaxed volume' in data:
                    volume = data['relaxed volume']
                else:
                    volume = atoms.get_volume()
                volumes = data['strains']**3 * volume
                energies = data['energies']
                eos = FullEquationOfState(volumes, energies)
                try:
                    v, e, B0, B1, R = eos.fit()
                except ValueError:
                    pass
                else:
                    data['dcdft fitted energy'] = e / len(atoms)
                    data['dcdft volume'] = v / len(atoms)
                    data['dcdft B0'] = B0
                    data['dcdft B1'] = B1
                    data['dcdft R'] = R

        if atomsfile:
            # MDTMP: TODO
            atomdata = read_json(atomsfile)
            for name, data in self.data.items():
                atoms = self.create_system(name)
                e = -data['energy']
                for atom in atoms:
                    e += atomdata[atom.symbol]['energy']
                e /= len(atoms)
                data['cohesive energy'] = e
                if self.collection.xc == 'PBE':
                    eref = self.collection.data[name][7]
                else:
                    eref = self.collection.data[name][9]
                data['cohesive energy error [%]'] = (e / eref - 1) * 100

            self.summary_keys += [
                'cohesive energy', 'cohesive energy error [%]'
            ]
Пример #6
0
    def analyse(self, atomsfile=None):
        try:
            BulkTask.analyse(self)
        except ValueError: # allow fit outside of range
            pass

        for name, data in self.data.items():
            if 'strains' in data:
                atoms = self.create_system(name)
                # full equation of state
                # use relaxed volume if present
                if 'relaxed volume' in data:
                    volume = data['relaxed volume']
                else:
                    volume = atoms.get_volume()
                volumes = data['strains']**3 * volume
                energies = data['energies']
                eos = FullEquationOfState(volumes, energies)
                try:
                    v, e, B0, B1, R = eos.fit()
                except ValueError:
                    pass
                else:
                    data['dcdft fitted energy'] = e / len(atoms)
                    data['dcdft volume'] = v / len(atoms)
                    data['dcdft B0'] = B0
                    data['dcdft B1'] = B1
                    data['dcdft R'] = R

        if atomsfile:
            # MDTMP: TODO
            atomdata = read_json(atomsfile)
            for name, data in self.data.items():
                atoms = self.create_system(name)
                e = -data['energy']
                for atom in atoms:
                    e += atomdata[atom.symbol]['energy']
                e /= len(atoms)
                data['cohesive energy'] = e
                if self.collection.xc == 'PBE':
                    eref = self.collection.data[name][7]
                else:
                    eref = self.collection.data[name][9]
                data['cohesive energy error [%]'] = (e / eref - 1) * 100

            self.summary_keys += ['cohesive energy',
                                  'cohesive energy error [%]']
Пример #7
0
    def run_single(self, name):
        self.log('Running', name)
        try:
            atoms = self.create_system(name)
        except Exception:
            self.log(name, 'FAILED')
            traceback.print_exc(file=self.logfile)
            return

        atoms.calc = self.calcfactory(self.get_filename(name), atoms)

        tstart = time()

        try:
            data = self.calculate(name, atoms)
            if self.after:
                exec self.after
        except KeyboardInterrupt:
            raise
        except Exception:
            self.log(name, 'FAILED')
            traceback.print_exc(file=self.logfile)
            return

        tstop = time()
        data['time'] = tstop - tstart

        filename = self.get_filename(ext='json')
        try:
            self.lock.acquire()
            if os.path.isfile(filename):
                alldata = read_json(filename)
            else:
                alldata = {}
            alldata[name] = data
            write_json(filename, alldata)
        finally:
            self.lock.release()

        for write in self.write_funcs:
            filenamebase = self.get_filename(name)
            write(filenamebase, atoms, data)

        return atoms
Пример #8
0
    def run_single(self, name):
        self.log('Running', name)
        try:
            atoms = self.create_system(name)
        except Exception:
            self.log(name, 'FAILED')
            traceback.print_exc(file=self.logfile)
            return

        atoms.calc = self.calcfactory(self.get_filename(name), atoms)

        tstart = time()

        try:
            data = self.calculate(name, atoms)
            if self.after:
                exec self.after
        except KeyboardInterrupt:
            raise
        except Exception:
            self.log(name, 'FAILED')
            traceback.print_exc(file=self.logfile)
            return

        tstop = time()
        data['time'] = tstop - tstart

        filename = self.get_filename(ext='json')
        try:
            self.lock.acquire()
            if os.path.isfile(filename):
                alldata = read_json(filename)
            else:
                alldata = {}
            alldata[name] = data
            write_json(filename, alldata)
        finally:
            self.lock.release()

        for write in self.write_funcs:
            filenamebase = self.get_filename(name)
            write(filenamebase, atoms, data)

        return atoms
Пример #9
0
    def run(self, atoms, name):
        args = self.args

        if self.lock is None:
            # Create lock object:
            if args.use_lock_file:
                self.lock = Lock(self.get_filename(ext='lock'))
            else:
                self.lock = OpenLock()

        skip = False
        if args.use_lock_file:
            try:
                filename = self.get_filename(ext='json')
                self.lock.acquire()
                if os.path.isfile(filename):
                    data = read_json(filename)
                    if name in data:
                        skip = True
                    else:
                        data[name] = {}
                        write_json(filename, data)
                else:
                    write_json(filename, {name: {}})
            finally:
                self.lock.release()
        
        if not skip:
            self.set_calculator(atoms, name)

            tstart = time.time()
            try:
                data = self.calculate(atoms, name)
            except KeyboardInterrupt:
                raise
            except Exception:
                self.log(name, 'FAILED')
                traceback.print_exc(file=self.logfile)
            else:
                tstop = time.time()
                data['time'] = tstop - tstart
                self.write(name, data)
Пример #10
0
from ase.data.g2_1_ref import ex_atomization, atomization
from ase.tasks.io import read_json
from ase.atoms import string2symbols
from ase.units import kcal, mol

data = read_json('molecule-pw.json')

maepbe = 0.0
maeexx = 0.0
print('                 PBE                   EXX')
print('-' * 48)
for name in ex_atomization:
    epberef = atomization[name][2] * kcal / mol
    epbe = (sum(data[atom]['energy'] for atom in string2symbols(name)) -
            data[name]['energy'])
    eexxref = ex_atomization[name][0] * kcal / mol
    eexx = (sum(data[atom]['energy'] + data[atom]['EXX']
                for atom in string2symbols(name)) -
            data[name]['energy'] - data[name]['EXX'])

    maepbe += abs(epbe - epberef) / len(ex_atomization)
    maeexx += abs(eexx - eexxref) / len(ex_atomization)

    print('%-4s %10.3f %10.3f %10.3f %10.3f' %
          (name, epbe, epbe - epberef, eexx, eexx - eexxref))

print('-' * 48)
print('MAE  %10.3f %10.3f %10.3f %10.3f' % (0, maepbe, 0, maeexx))

assert maepbe < 0.025
assert maeexx < 0.05
Пример #11
0
 def read(self, skipempty=True):
     self.data = read_json(self.get_filename(ext='json'))
     if skipempty:
         self.data = dict((key.encode('ascii'), value)
                          for key, value in self.data.items()
                          if value)
Пример #12
0
    def analyse(self, atomsfile=None):
        try:
            BulkTask.analyse(self)
        except ValueError:  # allow fit outside of range
            pass

        for name, data in self.data.items():
            if 'strains' in data:
                atoms = self.create_system(name)
                # use relaxed volume if present
                if 'relaxed volume' in data:
                    volume = data['relaxed volume']
                else:
                    volume = atoms.get_volume()
                volumes = data['strains']**3 * volume
                energies = data['energies']
                # allow selection of eos type independent of data
                if self.eos is not None:
                    eos = EquationOfState(volumes, energies, self.eos)
                else:
                    eos = EquationOfState(volumes, energies)
                try:
                    v, e, B = eos.fit()
                except ValueError:
                    pass
                else:
                    data['fitted energy'] = e
                    data['volume'] = v
                    data['B'] = B
                # with respect tot the reference volume
                data['volume error [%]'] = (
                    data['volume'] / atoms.get_volume() - 1) * 100
                if self.collection.B:
                    i = self.collection.labels.index(self.collection.xc) - 1
                    B = self.collection.B[name][i] * units.kJ * 1e-24
                    data['B error [%]'] = (data['B'] / B - 1) * 100
                else:
                    data['B error [%]'] = None
                data['strukturbericht'] = self.collection.data[name][0]
                data['crystal structure'] = strukturbericht[
                    data['strukturbericht']]
                # calculate lattice constant from volume
                cs = data['crystal structure']
                if cs == 'bcc':
                    a0 = (volume * 2)**(1 / 3.)
                    a = (data['volume'] * 2)**(1 / 3.)
                elif cs == 'cesiumchloride':
                    a0 = (volume)**(1 / 3.)
                    a = (data['volume'])**(1 / 3.)
                elif cs in [
                        'fcc', 'diamond', 'zincblende', 'rocksalt', 'fluorite'
                ]:
                    a0 = (volume * 4)**(1 / 3.)
                    a = (data['volume'] * 4)**(1 / 3.)
                i = self.collection.labels.index(self.collection.xc) - 1
                a0_ref = self.collection.data[name][i]
                if 'relaxed volume' not in data:
                    # no volume relaxation performed - volume equals the reference one
                    assert abs(a0 - a0_ref) < 1.e-4
                data['lattice constant'] = a
                data['lattice constant error [%]'] = (a -
                                                      a0_ref) / a0_ref * 100

        if atomsfile:
            # MDTMP: TODO
            atomdata = read_json(atomsfile)
            for name, data in self.data.items():
                atoms = self.create_system(name)
                e = -data['energy']
                for atom in atoms:
                    e += atomdata[atom.symbol]['energy']
                e /= len(atoms)
                data['cohesive energy'] = e
                if self.collection.xc == 'PBE':
                    eref = self.collection.data[name][7]
                else:
                    eref = self.collection.data[name][9]
                data['cohesive energy error [%]'] = (e / eref - 1) * 100

            self.summary_keys += [
                'cohesive energy', 'cohesive energy error [%]'
            ]
Пример #13
0
    def analyse(self, atomsfile=None):
        try:
            BulkTask.analyse(self)
        except ValueError: # allow fit outside of range
            pass

        for name, data in self.data.items():
            if 'strains' in data:
                atoms = self.create_system(name)
                # use relaxed volume if present
                if 'relaxed volume' in data:
                    volume = data['relaxed volume']
                else:
                    volume = atoms.get_volume()
                volumes = data['strains']**3 * volume
                energies = data['energies']
                # allow selection of eos type independent of data
                if self.eos is not None:
                    eos = EquationOfState(volumes, energies, self.eos)
                else:
                    eos = EquationOfState(volumes, energies)
                try:
                    v, e, B = eos.fit()
                except ValueError:
                    pass
                else:
                    data['fitted energy'] = e
                    data['volume'] = v
                    data['B'] = B
                # with respect tot the reference volume
                data['volume error [%]'] = (data['volume'] / atoms.get_volume() - 1) * 100
                if self.collection.B:
                    i = self.collection.labels.index(self.collection.xc) - 1
                    B = self.collection.B[name][i] * units.kJ * 1e-24
                    data['B error [%]'] = (data['B'] / B - 1) * 100
                else:
                    data['B error [%]'] = None
                data['strukturbericht'] = self.collection.data[name][0]
                data['crystal structure'] = strukturbericht[data['strukturbericht']]
                # calculate lattice constant from volume
                cs = data['crystal structure']
                if cs == 'bcc':
                    a0 = (volume*2)**(1/3.)
                    a = (data['volume']*2)**(1/3.)
                elif cs == 'cesiumchloride':
                    a0 = (volume)**(1/3.)
                    a = (data['volume'])**(1/3.)
                elif cs in ['fcc',
                            'diamond',
                            'zincblende',
                            'rocksalt',
                            'fluorite']:
                    a0 = (volume*4)**(1/3.)
                    a = (data['volume']*4)**(1/3.)
                i = self.collection.labels.index(self.collection.xc) - 1
                a0_ref = self.collection.data[name][i]
                if 'relaxed volume' not in data:
                    # no volume relaxation performed - volume equals the reference one
                    assert abs(a0 - a0_ref) < 1.e-4
                data['lattice constant'] = a
                data['lattice constant error [%]'] = (a - a0_ref) / a0_ref * 100

        if atomsfile:
            # MDTMP: TODO
            atomdata = read_json(atomsfile)
            for name, data in self.data.items():
                atoms = self.create_system(name)
                e = -data['energy']
                for atom in atoms:
                    e += atomdata[atom.symbol]['energy']
                e /= len(atoms)
                data['cohesive energy'] = e
                if self.collection.xc == 'PBE':
                    eref = self.collection.data[name][7]
                else:
                    eref = self.collection.data[name][9]
                data['cohesive energy error [%]'] = (e / eref - 1) * 100

            self.summary_keys += ['cohesive energy',
                                  'cohesive energy error [%]']
Пример #14
0
    def run(self, names=None):
        """Run task for all names.

        The task will be one of these four:

        * Open ASE's GUI
        * Write configuration to file
        * Write summary
        * Do the actual calculation
        """

        if self.lock is None:
            # Create lock object:
            self.lock = Lock(self.get_filename(ext='lock'))

        if self.clean:
            self.clean_json_file(names)
            return

        if names is None or len(names) == 0:
            names = self.collection.keys()

        names = self.expand(names)
        names = names[self.slice]
        names = self.exclude(names)

        if self.gui:
            for name in names:
                view(self.create_system(name))
            return

        if self.write_to_file:
            if self.write_to_file[0] == '.':
                for name in names:
                    filename = self.get_filename(name, self.write_to_file)
                    write(filename, self.create_system(name))
            else:
                assert len(names) == 1
                write(self.write_to_file, self.create_system(names[0]))
            return

        if self.write_summary:
            self.read()
            self.analyse()
            self.summarize(names)
            return

        atoms = None
        for name in names:
            if self.use_lock_files:
                try:
                    filename = self.get_filename(ext='json')
                    self.lock.acquire()
                    if os.path.isfile(filename):
                        data = read_json(filename)
                        if name not in data:
                            data[name] = {}
                            write_json(filename, data)
                        else:
                            self.log('Skipping', name)
                            continue
                    else:
                        write_json(filename, {name: {}})
                finally:
                    self.lock.release()

            if atoms is not None:
                del atoms.calc
            atoms = self.run_single(name)

        return atoms
Пример #15
0
 def read(self, skipempty=True):
     self.data = read_json(self.get_filename(ext='json'))
     if skipempty:
         self.data = dict((key.encode('ascii'), value)
                          for key, value in self.data.items() if value)
Пример #16
0
 def read(self):
     filename = self.get_filename(ext="json")
     return read_json(filename)
Пример #17
0
    def run(self, names=None):
        """Run task for all names.

        The task will be one of these four:

        * Open ASE's GUI
        * Write configuration to file
        * Write summary
        * Do the actual calculation
        """

        if self.lock is None:
            # Create lock object:
            self.lock = Lock(self.get_filename(ext='lock'))

        if self.clean:
            self.clean_json_file(names)
            return

        if names is None or len(names) == 0:
            names = self.collection.keys()

        names = self.expand(names)
        names = names[self.slice]
        names = self.exclude(names)

        if self.gui:
            for name in names:
                view(self.create_system(name))
            return

        if self.write_to_file:
            if self.write_to_file[0] == '.':
                for name in names:
                    filename = self.get_filename(name, self.write_to_file)
                    write(filename, self.create_system(name))
            else:
                assert len(names) == 1
                write(self.write_to_file, self.create_system(names[0]))
            return

        if self.write_summary:
            self.read()
            self.analyse()
            self.summarize(names)
            return

        atoms = None
        for name in names:
            if self.use_lock_files:
                try:
                    filename = self.get_filename(ext='json')
                    self.lock.acquire()
                    if os.path.isfile(filename):
                        data = read_json(filename)
                        if name not in data:
                            data[name] = {}
                            write_json(filename, data)
                        else:
                            self.log('Skipping', name)
                            continue
                    else:
                        write_json(filename, {name: {}})
                finally:
                    self.lock.release()

            if atoms is not None:
                del atoms.calc
            atoms = self.run_single(name)

        return atoms