materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.5k stars 862 forks source link

'diff' parameter not working in StructureGraph.draw_graph_to_file #2542

Open Anny-tech opened 2 years ago

Anny-tech commented 2 years ago

Describe the bug 'diff' parameter not working in 'draw_graph_to_file' from StructureGraph class of the pymatgen.analysis.graphs module

To Reproduce Steps to reproduce the behavior:

  1. Generated structure using *.cif file
  2. Generated structuregraph using 'with_local_env_strategy', with strategy=CrystalNN() in the StructureGraph class.
  3. Tried to generate graph image using st1_1.draw_graph_to_file(filename='graph.png',diff=st2_1), where st1_1= structuregraph1 and st2_1=structuregraph2.
  4. Error: [TypeError: 'ValueError' object is not subscriptable]

Screenshots image

Desktop (please complete the following information):

mkhorton commented 2 years ago

Hi @Anny-tech, thanks for the report. To be able to reproduce, could you supply the input structure too?

My suggestions are:

  1. Try st1_1.diff(st2_1) first. This calls the .diff() method which needs to work for the drawing method to work, and if this gives an error it may be more helpful.
  2. Bear in mind that the intent for this method is to compare different bonding strategies for the same structure. Trying to do a comparison between different structures will not be meaningful, since the nodes of the graph (atomic sites) are also different, not just the edges (bonds).
Anny-tech commented 2 years ago

Hi @mkhorton , thanks for the reply.

  1. I tried this already. It works. As in gives a Valu st1.cif.txt st2.cif.txt eError, with the same statement you mentioned in point 2 above.
  2. That is exactly our aim. I derived the structures from another code. Wanted to check using pymatgen whether the structures are indeed different or not! I am attaching the input structures here.
mkhorton commented 2 years ago

Ok, for this application maybe StructureMatcher maybe more appropriate. This can compare structures based on atomic co-ordinates and tell you if they are the same structure or not. The StructureGraph.diff methods are more for differences in number of bonds; it's possible for two different polymorphs (with different symmetries) to have the same bonds/graphs if their respective atoms are in the same co-ordination environments.