-
Notifications
You must be signed in to change notification settings - Fork 99
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
ElasticMaker
flow fails with MAGMOM
settings when using MP API data.
#1049
Comments
hongyi-zhao
changed the title
Nov 15, 2024
ElasticMaker
flow fails with MAGMOM
settings data when using MP API data.ElasticMaker
flow fails with MAGMOM
settings when using MP API data.
To update the MAGMOMs via The alternative is to add the magmoms to the site properties of a structure, and atomate2 will automatically read those in as MAGMOM:
|
In general, it should be used this way: def apply_magmoms_from_incar(structure, incar_settings):
"""
Apply magnetic moments from INCAR settings to structure, handling multiple species.
Args:
structure: pymatgen Structure object
incar_settings: dict containing INCAR settings including MAGMOM
"""
if "MAGMOM" not in incar_settings:
print("No MAGMOM settings found in INCAR")
return structure
magmoms = incar_settings.pop("MAGMOM")
# Check if number of MAGMOMs matches number of sites
if len(magmoms) == len(structure):
# Direct 1:1 mapping case
structure.add_site_property("magmom", magmoms)
else:
# Need to expand magmoms based on unique species
# Get unique species and their counts
species_counts = structure.composition.as_dict()
# Create expanded magmom list matching structure sites
site_magmoms = []
magmom_idx = 0
# Iterate through sites and assign magmoms
for site in structure:
site_magmoms.append(magmoms[magmom_idx])
# Check if we need to move to next magmom value
next_species_sites = structure.indices_from_symbol(site.species_string)
if len(site_magmoms) == max(next_species_sites) + 1:
magmom_idx += 1
structure.add_site_property("magmom", site_magmoms)
return structure
# 使用示例:
structure = apply_magmoms_from_incar(structure, incar_settings)
# 验证结果
print("Site properties:", structure.site_properties)
print("\nDetailed site information:")
for i, site in enumerate(structure):
print(f"Site {i}: {site.species_string} at {site.frac_coords}, "
f"magmom = {site.properties.get('magmom')}") The output:
The updated result of In [24]: structure.site_properties
Out[24]: {'magmom': [-0.002, -0.002, -0.002, -0.002]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The testing code below is adapted from my example here:
But the above code will trigger the following error:
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 snippetConvert MAGMOM list to dictionary format
shown above?Regards,
Zhao
The text was updated successfully, but these errors were encountered: