Exemplo n.º 1
0
def get_m_graph_from_site_data(s_data):
    mol = Molecule.from_sites([Site.from_dict(isite)
                               for isite in s_data['local_graph']['sites']])
    mg = MoleculeGraph.with_empty_graph(mol)
    for i in range(1, len(mg)):
        mg.add_edge(0, i)
    return mg
Exemplo n.º 2
0
def get_scene(data, site_index):
    site_data = data['site_data'][site_index]
    mol = Molecule.from_sites([Site.from_dict(isite)
                               for isite in site_data['local_graph']['sites']])
    scene = get_m_graph_from_mol(mol).get_scene()
    scene.name = "ref-site"
    return scene
Exemplo n.º 3
0
    def __init__(self, fname):
        """
        Initialize the cube object and store the data as self.data
        Args:
            fname (str): filename of the cube to read
        """
        f = zopen(fname, "rt")

        # skip header lines
        for i in range(2):
            f.readline()

        # number of atoms included in the file followed by the position of the origin of the volumetric data
        line = f.readline().split()
        self.natoms = int(line[0])
        self.origin = np.array(np.array(list(map(float, line[1:]))))

        # The next three lines give the number of voxels along each axis (x, y, z) followed by the axis vector.
        line = f.readline().split()
        self.NX = int(line[0])
        self.X = np.array([bohr_to_angstrom * float(l) for l in line[1:]])

        line = f.readline().split()
        self.NY = int(line[0])
        self.Y = np.array([bohr_to_angstrom * float(l) for l in line[1:]])

        line = f.readline().split()
        self.NZ = int(line[0])
        self.Z = np.array([bohr_to_angstrom * float(l) for l in line[1:]])

        self.voxelVolume = abs(np.dot(np.cross(self.X, self.Y), self.Z))
        self.volume = abs(
            np.dot(np.cross(self.X.dot(self.NZ), self.Y.dot(self.NY)),
                   self.Z.dot(self.NZ)))

        # The last section in the header is one line for each atom consisting of 5 numbers,
        # the first is the atom number, second is charge, the last three are the x,y,z coordinates of the atom center.
        self.sites = []
        for i in range(self.natoms):
            line = f.readline().split()
            self.sites.append(
                Site(line[0],
                     np.multiply(bohr_to_angstrom, list(map(float,
                                                            line[2:])))))

        self.structure = Structure(
            lattice=[self.X * self.NX, self.Y * self.NY, self.Z * self.NZ],
            species=[s.specie for s in self.sites],
            coords=[s.coords for s in self.sites],
            coords_are_cartesian=True)

        # Volumetric data
        self.data = np.zeros((self.NX, self.NY, self.NZ))
        i = 0
        for s in f:
            for v in s.split():
                self.data[int(i / (self.NY * self.NZ)),
                          int((i / self.NZ) % self.NY),
                          int(i % self.NZ), ] = float(v)
                i += 1
Exemplo n.º 4
0
 def compose_vasp_movie(self, diffusion_sites, empty_lattice):
     for i in diffusion_sites:
         site_from_dict = Site.from_dict(i)
         species = str(site_from_dict.specie)
         coords = site_from_dict.coords
         empty_lattice.append(species, coords, coords_are_cartesian=True)
     # writer.write_structure(empty_lattice, "POSCAR.path.vasp")
     return
Exemplo n.º 5
0
    def get_scene_and_legend(self,
                             scene_additions=None
                             ) -> Tuple[Scene, Dict[str, str]]:

        legend = Legend(self.graph.structure,
                        color_scheme="VESTA",
                        radius_scheme="uniform",
                        cmap_range=None)
        legend.uniform_radius = 0.2

        scene = get_structure_graph_scene(
            self.graph,
            draw_image_atoms=True,
            bonded_sites_outside_unit_cell=False,
            hide_incomplete_edges=True,
            explicitly_calculate_polyhedra_hull=False,
            group_by_symmetry=False,
            legend=legend)

        scene.name = "DefectStructureComponentScene"

        # axes = graph.structure.lattice._axes_from_lattice()
        # axes.visible = True
        # scene.contents.append(axes)

        scene = scene.to_json()
        if scene_additions:
            scene["contents"].append(scene_additions)

        lattice = self.graph.structure.lattice
        origin = -self.graph.structure.lattice.get_cartesian_coords(
            [0.5, 0.5, 0.5])

        for name, frac_coords in self.vacancy_sites:
            site = Site(species=DummySpecie(name),
                        coords=lattice.get_cartesian_coords(frac_coords))
            vac_scene = site.get_scene(origin=origin)
            vac_scene.name = f"{name}_{frac_coords}"
            vac_scene.contents[0].contents[0].tooltip = name
            scene["contents"].append(vac_scene.to_json())

        return scene, legend.get_legend()
Exemplo n.º 6
0
 def struct_or_mol(self):
     if isinstance(self._struct_or_mol, Molecule):
         for i, site in enumerate(self._struct_or_mol.sites):
             self._struct_or_mol._sites[i] = Site(
                 site.species,
                 self.data[i].ravel(),
                 properties=site.properties)
     elif isinstance(self._struct_or_mol, Structure):
         for i, site in enumerate(self._struct_or_mol.sites):
             fcoords = self._struct_or_mol._lattice.get_fractional_coords(
                 self.data[i].ravel())
             self._struct_or_mol._sites[i].frac_coords = fcoords
     else:
         pass
     return self._struct_or_mol
Exemplo n.º 7
0
def get_closest_matched(ref_data, site_index, all_random_sites):
    """
    Find the 10 most similar sites
    Args:
        ref_data:
        site_index:
        all_random_sites:

    Returns:

    """
    ref_soap_vec = ref_data['site_data'][site_index]['soap_vec']

    def similarity(random_site_data):
        return np.abs(1 - np.dot(random_site_data, ref_soap_vec) / np.dot(ref_soap_vec, ref_soap_vec))

    all_sites_with_sim = [(isite, similarity(isite['soap_vec']))
                          for isite in all_random_sites]
    all_sites_with_sim.sort(key=lambda x: x[1])

    matched_res = []
    for itr, (site_info, proj) in enumerate(all_sites_with_sim[:3]):
        mol = Molecule.from_sites([Site.from_dict(isite)
                                   for isite in site_info['local_graph']['sites']])
        mg = get_m_graph_from_mol(mol)
        scene = mg.get_scene()
        scene.name = f"matched-site-{itr}"
        matched_res.append(site_info["task_id"] + "   " + f"{proj:0.4f}")
        matched_res.append(Simple3DScene(
            sceneSize=210,
            inletSize=150,
            inletPadding=0,
            axisView='SW',
            data=scene
        ))
    return matched_res
Exemplo n.º 8
0
from pymatgen.electronic_structure.dos import CompleteDos, Dos
from pymatgen import Spin, Site, Orbital
from pymatgen.io.vasp import Vasprun

from vise.analyzer.vasp.dos_data import DosDataFromVasp
from vise.analyzer.plot_dos import DosPlotter


efermi = 0.5
energies = [-1, 0, 1]
tdos = [3, 4, 5]
pdos = [1, 2, 3]

total_dos = Dos(efermi=efermi, energies=energies,
                densities={Spin.up: tdos})
pdoses = {Site("H", [0, 0, 0]): {Orbital.s: {Spin.up: pdos},
                                 Orbital.px: {Spin.up: pdos},
                                 Orbital.py: {Spin.up: pdos},
                                 Orbital.pz: {Spin.up: pdos},
                                 Orbital.dxy: {Spin.up: pdos},
                                 Orbital.dyz: {Spin.up: pdos},
                                 Orbital.dxz: {Spin.up: pdos},
                                 Orbital.dz2: {Spin.up: pdos},
                                 Orbital.dx2: {Spin.up: pdos}}}


@pytest.fixture
def dos_data_from_vasp(mocker):
    stub_vasprun = mocker.Mock(spec=Vasprun)
    stub_vasprun.complete_dos = CompleteDos(None, total_dos, pdoses)
    return DosDataFromVasp(stub_vasprun).make_dos_data()