@@ -281,8 +281,10 @@ class DictSet(VaspInputSet):
281
281
structure and the configuration settings. The order in which the magmom is
282
282
determined is as follows:
283
283
284
- 1. If the site itself has a magmom setting (`site.magmom`), that is used.
285
- 2. If the species on the site has a spin setting (`site.spin`), that is used.
284
+ 1. If the site itself has a magmom setting (i.e. site.properties["magmom"] = float),
285
+ that is used. This can be set with structure.add_site_property().
286
+ 2. If the species of the site has a spin setting, that is used. This can be set
287
+ with structure.add_spin_by_element().
286
288
3. If the species itself has a particular setting in the config file, that
287
289
is used, e.g., Mn3+ may have a different magmom than Mn4+.
288
290
4. Lastly, the element symbol itself is checked in the config file. If
@@ -374,7 +376,7 @@ def __init__(
374
376
international_monoclinic (bool): Whether to use international convention
375
377
(vs Curtarolo) for monoclinic. Defaults True.
376
378
validate_magmom (bool): Ensure that the missing magmom values are filled
377
- in with the vasp default value of 1.0
379
+ in with the VASP default value of 1.0
378
380
"""
379
381
if reduce_structure :
380
382
structure = structure .get_reduced_structure (reduce_structure )
@@ -503,38 +505,30 @@ def incar(self) -> Incar:
503
505
if k == "MAGMOM" :
504
506
mag = []
505
507
for site in structure :
508
+ if v and not isinstance (v , dict ):
509
+ raise TypeError (
510
+ "MAGMOM must be supplied in a dictionary format, e.g. {'Fe': 5}. "
511
+ "If you want site-specific magnetic moments, set them in the site magmom properties "
512
+ "of the site objects in the structure."
513
+ )
506
514
if hasattr (site , "magmom" ):
507
515
mag .append (site .magmom )
508
516
elif hasattr (site .specie , "spin" ):
509
517
mag .append (site .specie .spin )
510
518
elif str (site .specie ) in v :
511
- if not isinstance (v , dict ):
512
- raise TypeError (
513
- "MAGMOM must be supplied in a dictionary format, e.g. {'Fe': 5}. "
514
- "If you want site-specific magnetic moments, set them in the site.magmom properties "
515
- "of the site objects in the structure"
516
- )
517
- if site .specie .symbol == "Co" :
519
+ if site .specie .symbol == "Co" and v [str (site .specie )] <= 1.0 :
518
520
warnings .warn (
519
- "Co without an oxidation state is initialized as low spin by default in Pymatgen "
520
- "(unless you have provided a MAGMOM dictionary specifying otherwise). If this default "
521
- "behavior is not desired, please set the spin on the magmom on the site directly to "
522
- "ensure correct initialization"
521
+ "Co without an oxidation state is initialized as low spin by default in Pymatgen. "
522
+ "If this default behavior is not desired, please set the spin on the magmom on the "
523
+ "site directly to ensure correct initialization."
523
524
)
524
525
mag .append (v .get (str (site .specie )))
525
526
else :
526
- if not isinstance (v , dict ):
527
- raise TypeError (
528
- "MAGMOM must be supplied in a dictionary format, e.g. {'Fe': 5}. "
529
- "If you want site-specific magnetic moments, set them in the site.magmom properties "
530
- "of the site objects in the structure"
531
- )
532
527
if site .specie .symbol == "Co" :
533
528
warnings .warn (
534
- "Co without an oxidation state is initialized as low spin by default in Pymatgen "
535
- "(unless you have provided a MAGMOM dictionary specifying otherwise). If this default "
536
- "behavior is not desired, please set the spin on the magmom on the site directly to "
537
- "ensure correct initialization"
529
+ "Co without an oxidation state is initialized as low spin by default in Pymatgen. "
530
+ "If this default behavior is not desired, please set the spin on the magmom on the "
531
+ "site directly to ensure correct initialization."
538
532
)
539
533
mag .append (v .get (site .specie .symbol , 0.6 ))
540
534
incar [k ] = mag
@@ -582,11 +576,11 @@ def incar(self) -> Incar:
582
576
incar ["LMAXMIX" ] = 4
583
577
584
578
# Warn user about LASPH for +U, meta-GGAs, hybrids, and vdW-DF
585
- if not settings .get ("LASPH" , False ) and (
586
- settings .get ("METAGGA" )
587
- or settings .get ("LHFCALC" , False )
588
- or settings .get ("LDAU" , False )
589
- or settings .get ("LUSE_VDW" , False )
579
+ if not incar .get ("LASPH" , False ) and (
580
+ incar .get ("METAGGA" )
581
+ or incar .get ("LHFCALC" , False )
582
+ or incar .get ("LDAU" , False )
583
+ or incar .get ("LUSE_VDW" , False )
590
584
):
591
585
warnings .warn (
592
586
"LASPH = True should be set for +U, meta-GGAs, hybrids, and vdW-DFT" ,
@@ -3076,7 +3070,7 @@ def batch_write_input(
3076
3070
3077
3071
def get_valid_magmom_struct (structure , inplace = True , spin_mode = "auto" ):
3078
3072
"""
3079
- Make sure that the structure is valid magmoms based on the kind of caculation
3073
+ Make sure that the structure has valid magmoms based on the kind of caculation
3080
3074
Fill in missing Magmom values
3081
3075
3082
3076
Args:
@@ -3099,10 +3093,12 @@ def get_valid_magmom_struct(structure, inplace=True, spin_mode="auto"):
3099
3093
for isite in structure .sites :
3100
3094
if "magmom" not in isite .properties or isite .properties ["magmom" ] is None :
3101
3095
pass
3102
- elif isinstance (isite .properties ["magmom" ], float ):
3096
+ elif isinstance (isite .properties ["magmom" ], ( float , int ) ):
3103
3097
if mode == "v" :
3104
3098
raise TypeError ("Magmom type conflict" )
3105
3099
mode = "s"
3100
+ if isinstance (isite .properties ["magmom" ], int ):
3101
+ isite .properties ["magmom" ] = float (isite .properties ["magmom" ])
3106
3102
elif len (isite .properties ["magmom" ]) == 3 :
3107
3103
if mode == "s" :
3108
3104
raise TypeError ("Magmom type conflict" )
0 commit comments