def _read(self): if self._names: return bigdct = read_json(self.filename) for id in bigdct["ids"]: dct = bigdct[id] kvp = dct["key_value_pairs"] name = str(kvp["name"]) self._names.append(name) self._systems[name] = AtomsRow(dct).toatoms() del kvp["name"] self._data[name] = dict((str(k), v) for k, v in kvp.items())
def _read_json(self): bigdct = read_json(self.filename) ids = bigdct['ids'] if not isinstance(ids, list): ids = ids.tolist() return bigdct, ids, bigdct['nextid']
# hubbard value = U = IE - EA = 13.59844 - 0.75497 = 12.84347 [eV] U_p = 12.84347 / Ha else: U_p = atom.get_hubbard_value(nls, scheme='central', maxstep=1.) atom.info['hubbardvalues'] = {'s': U_p} atom.info['occupations'] = occupations # Creating a DFTB+ band structure evaluator and # supplying it with a reference (DFT) band structure dpbs = DftbPlusBandStructure(Hamiltonian_SCC='Yes', Hamiltonian_OrbitalResolvedSCC='No', Hamiltonian_MaxAngularMomentum_='', Hamiltonian_MaxAngularMomentum_Br=lmax, Hamiltonian_PolynomialRepulsive='SetForAll {Yes}') bs_gpaw = read_json('bs_gpaw.json') # the reference band structure (DFT) atoms = bulk(element, struct, a=La, b=Lb, c=Lc, alpha=Lalpha) # see hotcent.tools.DftbPlusBandStructure for more information # on the various keyword arguments used below dpbs.add_reference_bandstructure(bs_gpaw, atoms=atoms, kpts_scf=kpts, reference_level='vbm', nsemicore=0, weight=1., distribution={ 'type': 'Boltzmann', 'kBT': 1.5 }) # Setting up and running the actual optimizer
# hubbard value = U = IE - EA = 13.59844 - 0.75497 = 12.84347 [eV] U_p = 12.84347/Ha else: U_p = atom.get_hubbard_value(nls, scheme='central', maxstep=1.) atom.info['hubbardvalues'] = {'s': U_p} atom.info['occupations'] = occupations # Creating a DFTB+ band structure evaluator and # supplying it with a reference (DFT) band structure dpbs = DftbPlusBandStructure(Hamiltonian_SCC='Yes', Hamiltonian_OrbitalResolvedSCC='No', Hamiltonian_MaxAngularMomentum_='', Hamiltonian_MaxAngularMomentum_As=lmax, Hamiltonian_PolynomialRepulsive='SetForAll {Yes}') bs_qe = read_json('bs_qe.json') # the reference band structure (DFT) atoms = bulk(element,struct,a=La,b=Lb,c=Lc,alpha=Lalpha) # see hotcent.tools.DftbPlusBandStructure for more information # on the various keyword arguments used below dpbs.add_reference_bandstructure(bs_qe, atoms=atoms, kpts_scf=kpts, reference_level='vbm', nsemicore=0, weight=1., distribution={'type': 'Boltzmann', 'kBT': 1.5}) # Setting up and running the actual optimizer # (the keyword arguments are known from hotcent.slako.SlaterKosterTable) confopt = ConfinementOptimizer(atom, N=500, rmin=0.4, dr=0.02, stride=4, superposition='density', xc=xc) # The initial confinement parameters are the same as in Tutorial #1. # The additional 'adjustable' keyword argument serves to indicate # which parameters are allowed to vary. Here we keep the quadratic
from ase.test import cli, require from ase.db import connect from ase.io.jsonio import read_json from ase.calculators.gaussian import Gaussian require('gaussian') cli("""\ ase-build O | ase-run gaussian -d gaussian_cmdline.json && ase-build O2 | ase-run gaussian -d gaussian_cmdline.json""") c = connect('gaussian_cmdline.json') dct = read_json('gaussian_cmdline.json') for name in ['O2', 'O']: d = c.get([('name', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = Gaussian.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('name=O').energy - c.get('name=O2').energy assert abs(ae - 1.060) < 1e-3
from ase.test import cli, require from ase.db import connect from ase.io.jsonio import read_json from ase.calculators.nwchem import NWChem require('nwchem') cli("""\ ase build O O.traj && ase run nwchem O.traj -o nwchem_cmdline.json && ase build O2 O2.traj && ase run nwchem O2.traj -o nwchem_cmdline.json""") c = connect('nwchem_cmdline.json') dct = read_json('nwchem_cmdline.json') for name in ['O2', 'O']: d = c.get([('formula', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = NWChem.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('formula=O').energy - c.get('formula=O2').energy assert abs(ae - 6.6053) < 1e-4
def read_json(self, filename): """Load Calculator state from an exported JSON Vasp2 file.""" dct = jsonio.read_json(filename) self.fromdict(dct)
def read_band_structure(filename): bs = read_json(filename) if not isinstance(bs, BandStructure): raise CLIError(f'Expected band structure, but file contains: {bs}') return bs
kpts={ 'path': 'WGKL', 'npoints': 20 }, convergence={'bands': 'all'}, ) calc.get_potential_energy() path = bandpath('WGKL', atoms.get_cell(), npoints=20) bs_dft = get_band_structure(atoms=atoms, calc=calc, path=path, reference=evbm) write_json('bs_dft.json', bs_dft) bs_dft = read_json('bs_dft.json') bs_dft.plot(filename='bs_dft.png', show=False, emax=bs_dft.reference + 10, emin=bs_dft.reference - 20) dpbs = DftbPlusBandStructure(Hamiltonian_SCC='Yes', Hamiltonian_OrbitalResolvedSCC='No', Hamiltonian_MaxAngularMomentum_='', Hamiltonian_MaxAngularMomentum_N='p', Hamiltonian_MaxAngularMomentum_O='p', Hamiltonian_PolynomialRepulsive='SetForAll {Yes}', Hamiltonian_SpinPolarisation='Colinear {', Hamiltonian_SpinPolarisation_UnpairedElectrons=1, Hamiltonian_SpinConstants_='', Hamiltonian_SpinConstants_O=-0.028,
def load(cls, path): # XXX Very hacky this one cache = cls(path, {}) dct = read_json(cache._filename, always_array=False) cache._dct.update(dct) return cache
def read_object(filename): try: return read(filename) except UnknownFileTypeError: # Probably a bandpath/bandstructure: return read_json(filename)
from datetime import datetime import numpy as np import io from ase.io.jsonio import encode, decode, read_json, write_json assert decode(encode(np.int64(42))) == 42 c = np.array([0.1j]) assert (decode(encode(c)) == c).all() fd = io.StringIO() obj1 = {'hello': 'world'} write_json(fd, obj1) fd.seek(0) obj2 = read_json(fd) print(obj1) print(obj2) for obj in [0.5 + 1.5j, datetime.now()]: s = encode(obj) o = decode(s) print(obj) print(s) print(obj) assert obj == o, (obj, o, s)
from ase.test import cli, require from ase.db import connect from ase.io.jsonio import read_json from ase.calculators.nwchem import NWChem require('nwchem') cli("""ase build O | ase run nwchem -d nwchem_cmdline.json && ase build O2 | ase run nwchem -d nwchem_cmdline.json""") c = connect('nwchem_cmdline.json') dct = read_json('nwchem_cmdline.json') for name in ['O2', 'O']: d = c.get([('name', '=', name)]) id = d.id e1 = d.energy e2 = c.get_atoms(id).get_potential_energy() e3 = NWChem.read_atoms(name).get_potential_energy() e4 = dct[id]['energy'] assert e1 == e2 == e3 == e4 print(e1) ae = 2 * c.get('name=O').energy - c.get('name=O2').energy assert abs(ae - 6.6053) < 1e-4
from ase.build import bulk from ase.dft.band_structure import calculate_band_structure from ase.io.jsonio import read_json from ase.calculators.test import FreeElectrons atoms = bulk('Au') lat, _ = atoms.cell.bravais() path = lat.bandpath(npoints=100) atoms.calc = FreeElectrons() bs = calculate_band_structure(atoms, path) bs.write('bs.json') bs.path.write('path.json') bs1 = read_json('bs.json') path1 = read_json('path.json') print(bs1) print(path1) assert type(bs1) == type(bs) assert type(path1) == type(bs.path)