Code Monkey home page Code Monkey logo

Comments (4)

janosh avatar janosh commented on June 11, 2024

when i first tried StructureVis 1-2 years ago i got the same behavior. not sure when it was last working. bug fix PRs welcome!

from pymatgen.

CharlesCardot avatar CharlesCardot commented on June 11, 2024

I've discovered that the issue is two-fold.

  1. I failed to read the documentation correctly and didn't realize that I needed to use the set_structure function on the newly created StructureVis object to actually give it something to render. That was why it was just showing a blank white window. My script should have been written like this.
from pymatgen.vis.structure_vtk import StructureVis
from pymatgen.core import Structure

structure = Structure.from_file("Ca2CuO3.cif")
vis = StructureVis()
vis.set_structure(structure)

vis.show()
  1. However, this script also errors out because of the add_polyhedron function in the structure_vtk module which gets called because show_polyhedron = True by default. When trying to figure out how to color the polyhedron, the module tries to make the polyhedron the same color as the center atom, but when the occupations of the center atom are fractional it will use the color of the center atom with the highest occupation.
        if color == "element":
            # If partial occupations are involved, the color of the specie with
            # the highest occupation is used
            max_occu = 0.0
            for specie, occu in center.species.items():
                if occu > max_occu:
                    max_specie = specie
                    max_occu = occu
            color = [i / 255 for i in self.el_color_mapping[max_specie.symbol]]
            ac.GetProperty().SetColor(color)
        else:
            ac.GetProperty().SetColor(color)

The main issue here is that the "color" variable is an array of fractional rgb values (ex: [1,0,0]), and I can't seem to find where this comparison against a string "element" comes from or why that was used. This can be solved relatively easily by either setting show_polyhedron = False when creating the StructureVis object, or by changing the condition to if len(center.species.items()) > 1:.

I don't have a lot of experience contributing to open source projects on github but I can try to submit a bug fix PR in the next couple days.

from pymatgen.

CharlesCardot avatar CharlesCardot commented on June 11, 2024

Update, I actually may have misrepresented the issue slightly. It doesn't actually have anything to do with whether the center atom has multiple occupations or not, it all just comes down to that check of if color == "element": and that at no point in the code does color ever seem to be stored as a string. I don't think the proposed solution should be any different though.

from pymatgen.

mkhorton avatar mkhorton commented on June 11, 2024

Yes, I don’t know that this is actively used. I would usually point people towards Crystal Toolkit since it has native support for Structure visualisation in Jupyter etc., however it’s in need of some updated documentation.

from pymatgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.