示例#1
0
def test_from_pmg_structure():

    pmg_struc = pmgstruc.Structure(lattice= np.eye(3),
                                   species=['H'],
                                   coords=[[.25, .5, 0]],
                                   site_properties={
                                       'force': [np.array((1., 1.,  1.))],
                                        'std':[np.array((1., 1., 1.))]},
                                   coords_are_cartesian=True)

    new_struc = Structure.from_pmg_structure(pmg_struc)

    assert len(new_struc) == 1

    assert np.equal(new_struc.positions, np.array([.25, .5, 0])).all()
    assert new_struc.coded_species == [1]
    assert new_struc.species_labels[0] == 'H'
    assert np.equal(new_struc.forces, np.array([1., 1., 1.])).all()

    pmg_struc = pmgstruc.Structure(lattice= np.diag([1.2,0.8,1.5]),
                                   species=['H'],
                                   coords=[[.25, .5, 0]],
                                   site_properties={
                                       'force': [np.array((1., 1.,  1.))],
                                        'std':[np.array((1., 1., 1.))]},
                                   coords_are_cartesian=True)

    new_struc = Structure.from_pmg_structure(pmg_struc)

    assert len(new_struc) == 1

    assert np.equal(new_struc.positions, np.array([.25, .5, 0])).all()
    assert new_struc.coded_species == [1]
    assert new_struc.species_labels[0] == 'H'
    assert np.equal(new_struc.forces, np.array([1., 1., 1.])).all()
示例#2
0
def parse_dft_input(input: str):
    """
    Returns the positions, species, and cell of a POSCAR file.
    Outputs are specced for OTF module.

    :param input: POSCAR file input
    :return:
    """

    pmg_structure = Poscar.from_file(input).structure
    flare_structure = Structure.from_pmg_structure(pmg_structure)

    positions = flare_structure.positions
    species = flare_structure.species_labels
    cell = flare_structure.cell
    # TODO Allow for custom masses in POSCAR

    elements = set(species)

    # conversion from amu to md units
    mass_dict = {
        elt: Element(elt).atomic_mass * 0.000103642695727
        for elt in elements
    }

    return positions, species, cell, mass_dict
示例#3
0
def test_from_pmg_structure():
    pmgstruc = pytest.importorskip("pymatgen.core.structure")

    pmg_struc = pmgstruc.Structure(
        lattice=np.eye(3),
        species=["H"],
        coords=[[0.25, 0.5, 0]],
        site_properties={
            "force": [np.array((1.0, 1.0, 1.0))],
            "std": [np.array((1.0, 1.0, 1.0))],
        },
        coords_are_cartesian=True,
    )

    new_struc = Structure.from_pmg_structure(pmg_struc)

    assert len(new_struc) == 1

    assert np.equal(new_struc.positions, np.array([0.25, 0.5, 0])).all()
    assert new_struc.coded_species == [1]
    assert new_struc.species_labels[0] == "H"
    assert np.equal(new_struc.forces, np.array([1.0, 1.0, 1.0])).all()

    pmg_struc = pmgstruc.Structure(
        lattice=np.diag([1.2, 0.8, 1.5]),
        species=["H"],
        coords=[[0.25, 0.5, 0]],
        site_properties={
            "force": [np.array((1.0, 1.0, 1.0))],
            "std": [np.array((1.0, 1.0, 1.0))],
        },
        coords_are_cartesian=True,
    )

    new_struc = Structure.from_pmg_structure(pmg_struc)

    assert len(new_struc) == 1

    assert np.equal(new_struc.positions, np.array([0.25, 0.5, 0])).all()
    assert new_struc.coded_species == [1]
    assert new_struc.species_labels[0] == "H"
    assert np.equal(new_struc.forces, np.array([1.0, 1.0, 1.0])).all()
示例#4
0
def md_trajectory_from_vasprun(vasprun, ionic_step_skips=1, vasprun_kwargs: dict = {}):
    """
    Returns a list of flare Structure objects decorated with forces, stress,
    and total energy from a MD trajectory performed in VASP.
    :param vasprun: pymatgen Vasprun object or vasprun filename
    :param ionic_step_skips: if True, only samples the configuration every
        ionic_skip_steps steps.
    """
    vasprun = check_vasprun(vasprun, vasprun_kwargs)

    struc_lst = []
    for step in vasprun.ionic_steps[::ionic_step_skips]:
        structure = Structure.from_pmg_structure(step["structure"])
        structure.energy = step["electronic_steps"][-1]["e_0_energy"]
        # TODO should choose e_wo_entrp or e_fr_energy?
        structure.forces = np.array(step.get("forces"))
        structure.stress = np.array(step.get("stress"))
        struc_lst.append(structure)

    return struc_lst
示例#5
0
def dft_input_to_structure(poscar: str):
    """
    Parse the DFT input in a directory.
    :param vasp_input: directory of vasp input
    """
    return Structure.from_pmg_structure(Poscar.from_file(poscar).structure)