Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the correct way to use the MAGMOM's value when using MP API data? #4173

Open
hongyi-zhao opened this issue Nov 15, 2024 · 0 comments
Open

Comments

@hongyi-zhao
Copy link
Contributor

The testing code below is adapted from my example here:

from mp_api.client import MPRester
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from atomate2.vasp.flows.mp import MPGGADoubleRelaxMaker
from atomate2.vasp.powerups import (
    update_user_incar_settings,
    update_user_potcar_functional,
)
from jobflow import run_locally

# Set POTCAR functional
user_potcar_functional = "PBE_64"

# Get structure from MP
material_id = "mp-126"
with MPRester() as mpr:
    # First get the task id from the materials doc
    materials = mpr.materials.search(material_ids=[material_id], fields=["task_ids"])
    task_id = materials[0].task_ids[0]
    
    # Now get the calculation that includes MAGMOM settings
    tasks = mpr.materials.tasks.search(task_ids=[task_id], 
        fields=["input.incar", "calcs_reversed"])
    
    # Get the INCAR settings from the calculation
    incar_settings = tasks[0].calcs_reversed[0].input.incar
    
    # Get the structure and convert to conventional cell
    structure = mpr.materials.get_structure_by_material_id(material_id)
    structure = SpacegroupAnalyzer(structure).get_conventional_standard_structure()

# Convert MAGMOM list to dictionary format
#if "MAGMOM" in incar_settings:
#    print("Original MAGMOM settings:", incar_settings["MAGMOM"])
#    print("Number of sites in structure:", len(structure))
#    
#    # Get unique species list
#    species_list = [site.species_string for site in structure]
#    unique_species = sorted(set(species_list))
#    print("Unique species in structure:", unique_species)
#    
#    # Set all species to the first MAGMOM value from the original calculation
#    magmom_dict = {specie: incar_settings["MAGMOM"][0] for specie in unique_species}
#    incar_settings["MAGMOM"] = magmom_dict
#    print("MAGMOM dictionary:", magmom_dict)

# Create a simple flow with just the relax
flow = MPGGADoubleRelaxMaker().make(structure)

# Update POTCAR settings
flow = update_user_potcar_functional(flow, user_potcar_functional)

# Update INCAR settings
flow = update_user_incar_settings(flow, incar_settings)

# Run the flow
responses = run_locally(flow, create_folders=True, ensure_success=True)

But the above code will trigger the following error:

Retrieving MaterialsDoc documents: 100%|████████████████████████████████| 1/1 [00:00<00:00, 12865.96it/s]
Retrieving TaskDoc documents: 100%|█████████████████████████████████████| 1/1 [00:00<00:00, 11715.93it/s]
Retrieving MaterialsDoc documents: 100%|████████████████████████████████| 1/1 [00:00<00:00, 11848.32it/s]
/home/werner/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/io/vasp/sets.py:288: BadInputSetWarning: Overriding the POTCAR functional is generally not recommended  as it significantly affects the results of calculations and compatibility with other calculations done with the same input set. Note that some POTCAR symbols specified in the configuration file may not be available in the selected functional.
  warnings.warn(
2024-11-10 08:41:06,924 INFO Started executing jobs locally
2024-11-10 08:41:06,926 INFO Starting job - MP GGA relax 1 (ecdb12aa-5e73-4d2b-97b3-d6deb29ce066)
2024-11-10 08:41:06,928 INFO MP GGA relax 1 failed with exception:
Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/jobflow/managers/local.py", line 114, in _run_job
    response = job.run(store=store)
               ^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/jobflow/core/job.py", line 600, in run
    response = function(*self.function_args, **self.function_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/Public/repo/github.com/materialsproject/atomate2.git/src/atomate2/vasp/jobs/base.py", line 219, in make
    write_vasp_input_set(
  File "/home/werner/Public/repo/github.com/materialsproject/atomate2.git/src/atomate2/vasp/files.py", line 190, in write_vasp_input_set
    vis = input_set_generator.get_input_set(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/io/vasp/sets.py", line 476, in get_input_set
    incar=self.incar,
          ^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/io/vasp/sets.py", line 572, in incar
    if uic_magmom := self.user_incar_settings.get("MAGMOM", {}).get(site.species_string):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'get'

2024-11-10 08:41:06,928 INFO Finished executing jobs locally
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[6], line 56
     53 flow = update_user_incar_settings(flow, incar_settings)
     55 # Run the flow
---> 56 responses = run_locally(flow, create_folders=True, ensure_success=True)

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/jobflow/managers/local.py:181, in run_locally(flow, log, store, create_folders, root_dir, ensure_success, allow_external_references, raise_immediately)
    178 logger.info("Finished executing jobs locally")
    180 if ensure_success and not finished_successfully:
--> 181     raise RuntimeError("Flow did not finish running successfully")
    183 return dict(responses)

RuntimeError: Flow did not finish running successfully

Is there a proper way to handle MAGMOM settings when copying from MP calculations without requiring further user adjustment, say, the one done by the code snippet Convert MAGMOM list to dictionary format shown above?

See materialsproject/atomate2#1049 for the related discussion.

Regards,
Zhao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant