def port(picklefile): picklefile = Path(picklefile) name = picklefile.name vibname, key, pckl = name.rsplit('.', 3) assert pckl == 'pckl' cache = MultiFileJSONCache(picklefile.parent / vibname) obj = pickle.loads(picklefile.read_bytes()) if isinstance(obj, np.ndarray): # vibrations dct = {'forces': obj} else: # Infrared forces, dipole = obj assert isinstance(forces, np.ndarray), f'not supported: {type(forces)}' assert isinstance(dipole, np.ndarray), f'not supported: {type(dipole)}' dct = {'forces': forces, 'dipole': dipole} outfilename = cache._filename(key) if key in cache: del cache[key] cache[key] = dct print(f'wrote {picklefile} ==> {outfilename}')
def __init__(self, atoms, calc=None, supercell=(1, 1, 1), name=None, delta=0.01, center_refcell=False): """Init with an instance of class ``Atoms`` and a calculator. Parameters: atoms: Atoms object The atoms to work on. calc: Calculator Calculator for the supercell calculation. supercell: tuple Size of supercell given by the number of repetitions (l, m, n) of the small unit cell in each direction. name: str Base name to use for files. delta: float Magnitude of displacement in Ang. center_refcell: bool Reference cell in which the atoms will be displaced. If False, then corner cell in supercell is used. If True, then cell in the center of the supercell is used. """ # Store atoms and calculator self.atoms = atoms self.calc = calc # Displace all atoms in the unit cell by default self.indices = np.arange(len(atoms)) self.name = name self.delta = delta self.center_refcell = center_refcell self.supercell = supercell self.cache = MultiFileJSONCache('phonons-cache')
def cache(): return MultiFileJSONCache('cache')
def __init__(self, name): self.cache = MultiFileJSONCache(name)