Example #1
0
def dict2atoms(row):
    from quippy.elasticity import stress_matrix

    at = row.toatoms(add_additional_information=True)

    f = None
    try:
        f = at.get_forces()
    except RuntimeError:
        pass

    e = None
    try:
        e = at.get_potential_energy()
    except RuntimeError:
        pass

    v = None
    try:
        v = -stress_matrix(at.get_stress()) * at.get_volume()
    except RuntimeError:
        pass

    at = Atoms(at)  # convert to quippy Atoms
    if f is not None:
        at.add_property('force', f.T)
    if e is not None:
        at.params['energy'] = e
    if v is not None:
        at.params['virial'] = v

    if 'key_value_pairs' in atoms.params:
        atoms.params.update(atoms.params['key_value_pairs'])
        del atoms.params['key_value_pairs']

    if 'data' in atoms.params:
        for (key, value) in atoms.params['data'].items():
            key = str(key)  # avoid unicode strings
            value = np.array(value)
            if value.dtype.kind == 'U':
                value = value.astype(str)
            if value.dtype.kind != 'S':
                value = value.T
            try:
                at.add_property(key, value)
            except (TypeError, RuntimeError):
                at.params[key] = value

    return at
Example #2
0
def ASEReader(source, format=None):
    """
    Helper routine to load from ASE trajectories
    """
    from ase.io import read
    from ase.atoms import Atoms as AseAtoms
    from quippy.elasticity import stress_matrix

    format_converter = {
        'POSCAR': 'vasp',
        'CONTCAR': 'vasp',
        'OUTCAR': 'vasp-out',
        'vasprun.xml': 'vasp-xml'
    }
    format = format_converter.get(format, format)
    images = read(source, index=slice(None, None, None), format=format)
    if isinstance(images, AseAtoms):
        images = [images]

    for at in images:
        f = None
        try:
            f = at.get_forces()
        except RuntimeError:
            pass

        e = None
        try:
            e = at.get_potential_energy(force_consistent=True)
        except RuntimeError:
            pass

        v = None
        try:
            v = -stress_matrix(at.get_stress()) * at.get_volume()
        except RuntimeError:
            pass

        at = Atoms(at)  # convert to quippy Atoms
        if f is not None:
            at.add_property('force', f.T)
        if e is not None:
            at.params['energy'] = e
        if v is not None:
            at.params['virial'] = v

        yield at
Example #3
0
 def callback(at):
     at.set_calculator(calculator)
     if at.calc_energy:
         at.params['energy'] = at.get_potential_energy()
     if at.calc_local_e:
         at.add_property('local_e', 0.0, overwrite=True)
         at.local_e[:] = at.get_potential_energies()
     if at.calc_force:
         at.add_property('force', 0.0, n_cols=3, overwrite=True)
         at.force[:] = at.get_forces().T
     if at.calc_virial:
         stress = at.get_stress()
         virial = fzeros((3, 3))
         virial[:, :] = stress_matrix(-stress * at.get_volume())
         at.params['virial'] = virial
     if at.calc_local_virial:
         stresses = at.get_stresses()
         at.add_property('local_virial', 0.0, n_cols=9, overwrite=True)
         lv = at.local_virial.view(np.ndarray)
         vol_per_atom = at.get_volume() / len(at)
         lv[...] = -stresses.T.reshape((len(at), 9)) * vol_per_atom
Example #4
0
def ASEReader(source):
    """
    Helper routine to load from ASE trajectories
    """
    from ase.io import read
    from ase.atoms import Atoms as AseAtoms
    from quippy.elasticity import stress_matrix

    images = read(source, index=slice(None, None, None))
    if isinstance(images, AseAtoms):
        images = [images]

    for at in images:
        f = None
        try:
            f = at.get_forces()
        except RuntimeError:
            pass

        e = None
        try:
            e = at.get_potential_energy()
        except RuntimeError:
            pass

        v = None
        try:
            v = -stress_matrix(at.get_stress()) * at.get_volume()
        except RuntimeError:
            pass

        at = Atoms(at)  # convert to quippy Atoms
        if f is not None:
            at.add_property('force', f.T)
        if e is not None:
            at.params['energy'] = e
        if v is not None:
            at.params['virial'] = v

        yield at