Repository: materialsproject/pymatgen

Issue #2499: Add a kwarg to avoid POTCAR checking in correction scheme
Created: 2022-04-20T09:26:30Z
This mainly concerns the MaterialsProject2020Compatibility scheme, so I'm CC'ing @rkingsbury here.

  
    
      pymatgen/pymatgen/entries/compatibility.py
    
    
        Lines 941 to 944
      in
      dcc4576
    
  
  
    

        
          
           # check the POTCAR symbols 
        

        
          
           # this should return ufloat(0, 0) or raise a CompatibilityError or ValueError 
        

        
          
           pc = PotcarCorrection(MPRelaxSet, check_hash=self.check_potcar_hash) 
        

        
          
           pc.get_correction(entry) 
        
    
  


The above codeblock checks the POTCAR symbols when getting a correction. While this is a very useful tool, I don't know that it should be required to obtain a correction. For instance, my entry objects don't have any data about POTCARs in them, but I can't get the corrections without commenting out this codeblock.
@rkingsbury: Are you opposed to me adding a kwarg check_potcar to get_adjustments() or to __init__ to optionally bypass this check? I feel like the difference between this and check_potcar_hash=False is potentially confusing though. In the case of check_potcar_hash, the POTCARs are still check but just their symbols and not the hash itself. Any suggestions?
For additional context, see #3142.

Duplicate issue #3142: `MaterialsProjectDFTMixingScheme.process_entries()` should have a kwarg to avoid POTCAR checks
Created: 2023-07-11T02:15:43Z
When using MaterialsProjectDFTMixingScheme.process_entries(), if the user does not provide ComputedStructureEntry objects with POTCAR symbols in .parameters, the mixing scheme will crash. While it's understandable to do a validity check by default, there should be a kwarg to disable this.
If a user is trying to use the MaterialsProjectDFTMixingScheme on calculations they ran manually (i.e. without Atomate), the procedure is something like:

Run VASP calculation with MP-compatible settings
Make a Structure and get the energy from the outputs
From that, make a ComputedStructureEntry
Run the ComputedStructureEntry objects through MaterialsProjectDFTMixingScheme alongside ComputedStructureEntry objects pulled from MP for that chemical system.

By default, this ComputedStructureEntry does not have (nor does it require) any information about the POTCARs used. When passing these ComputedStructureEntry objects to MaterialsProjectDFTMixingScheme, one would naively expect the mixing scheme to "just work," but instead it raises an error because the ComputedStructureEntry doesn't have the properties needed for a validity check. Pymatgen shouldn't expect the user to know to parse the POTCAR hash from the vasprun.xml or POTCAR and add it to the properties of the ComputedStructureEntry, especially when it's only needed for a validity check. Alternatively, there should be clearer documentation at the least.
On a related note, there should be some additional documentation that the user should be specifying .parameters["run_type"] and the related Hubbard parameters when constructing their ComputedStructureEntry objects. The way the mixing scheme currently works, it kind of assumes the user is familiar with the Atomate/MP entry format. This is very closely tied to #2500.
Edit: I realized this is basically the same issue as #2499 from a while ago. I'll keep this one open since it has a bit more context.

      1 scheme = MaterialsProjectDFTMixingScheme()
----> 2 corrected_entries = scheme.process_entries(entries)
      3 rosen_corrected_entries = [
      4     entry for entry in corrected_entries if "rosen" in entry.entry_id
      5 ]

File [c:\Users\asros\miniconda3\envs\cms\lib\site-packages\pymatgen\entries\mixing_scheme.py:178](file:///C:/Users/asros/miniconda3/envs/cms/lib/site-packages/pymatgen/entries/mixing_scheme.py:178), in MaterialsProjectDFTMixingScheme.process_entries(self, entries, clean, verbose, inplace, mixing_state_data)
    175         for ea in entry.energy_adjustments:
    176             entry.energy_adjustments.remove(ea)
--> 178 entries_type_1, entries_type_2 = self._filter_and_sort_entries(entries, verbose=verbose)
    180 if mixing_state_data is None:
    181     if verbose:

File [c:\Users\asros\miniconda3\envs\cms\lib\site-packages\pymatgen\entries\mixing_scheme.py:628](file:///C:/Users/asros/miniconda3/envs/cms/lib/site-packages/pymatgen/entries/mixing_scheme.py:628), in MaterialsProjectDFTMixingScheme._filter_and_sort_entries(self, entries, verbose)
    625 # preprocess entries with any corrections
    626 # make an EntrySet to enable some useful methods like .chemsys and .is_ground_state
    627 if self.compat_1:
--> 628     entries_type_1 = self.compat_1.process_entries(entries_type_1)
    629     if verbose:
    630         print(
    631             f"  Processed {len(entries_type_1)} compatible {self.run_type_1} entries with "
    632             f"{type(self.compat_1).__name__}"
    633         )

File [c:\Users\asros\miniconda3\envs\cms\lib\site-packages\pymatgen\entries\compatibility.py:587](file:///C:/Users/asros/miniconda3/envs/cms/lib/site-packages/pymatgen/entries/compatibility.py:587), in Compatibility.process_entries(self, entries, clean, verbose, inplace)
    584     entry.energy_adjustments = []
    586 try:  # get the energy adjustments
--> 587     adjustments = self.get_adjustments(entry)
    588 except CompatibilityError:
    589     continue

File [c:\Users\asros\miniconda3\envs\cms\lib\site-packages\pymatgen\entries\compatibility.py:941](file:///C:/Users/asros/miniconda3/envs/cms/lib/site-packages/pymatgen/entries/compatibility.py:941), in MaterialsProject2020Compatibility.get_adjustments(self, entry)
    939 if entry.parameters.get("software", "vasp") == "vasp":
    940     pc = PotcarCorrection(MPRelaxSet, check_hash=self.check_potcar_hash)
--> 941     pc.get_correction(entry)
    943 # apply energy adjustments
    944 adjustments: list[CompositionEnergyAdjustment] = []

File [c:\Users\asros\miniconda3\envs\cms\lib\site-packages\pymatgen\entries\compatibility.py:162](file:///C:/Users/asros/miniconda3/envs/cms/lib/site-packages/pymatgen/entries/compatibility.py:162), in PotcarCorrection.get_correction(self, entry)
    160     psp_settings = {d.get("titel").split()[1] for d in entry.parameters["potcar_spec"] if d}
    161 else:
--> 162     psp_settings = {sym.split()[1] for sym in entry.parameters["potcar_symbols"] if sym}
    164 if {self.valid_potcars.get(str(el)) for el in entry.composition.elements} != psp_settings:
    165     raise CompatibilityError("Incompatible potcar")

KeyError: 'potcar_symbols'

Closing comment (2023-07-11T03:27:40Z): Closing as a duplicate of #2499 because I forgot I opened a similar issue a year ago.