@@ -46,6 +46,10 @@ class is written.
46
46
47
47
# TODO: Add check for whether all ions have or lack velocities.
48
48
# TODO: Add default value filling like JDFTx does.
49
+ # TODO: Add more robust checking for if two repeatable tag values represent the
50
+ # same information. This is likely fixed by implementing filling of default values.
51
+ # TODO: Incorporate something to collapse repeated dump tags of the same frequency
52
+ # into a single value.
49
53
50
54
51
55
class JDFTXInfile (dict , MSONable ):
@@ -80,18 +84,34 @@ def __add__(self, other: JDFTXInfile) -> JDFTXInfile:
80
84
"""Add existing JDFTXInfile object to method caller JDFTXInfile object.
81
85
82
86
Add all the values of another JDFTXInfile object to this object. Facilitate the use of "standard" JDFTXInfiles.
87
+ Repeatable tags are appended together. Non-repeatable tags are replaced with their value from the other object.
83
88
84
89
Args:
85
90
other (JDFTXInfile): JDFTXInfile object to add to the method caller object.
86
91
87
92
Returns:
88
93
JDFTXInfile: The combined JDFTXInfile object.
89
94
"""
90
- params : dict [str , Any ] = dict (self .items ())
95
+ # Deepcopy needed here, or else in `jif1 = jif2 + jif3`, `jif1` will become a reference to `jif2`
96
+ params : dict [str , Any ] = deepcopy (dict (self .items ()))
91
97
for key , val in other .items ():
92
- if key in self and val != self [key ]:
93
- raise ValueError (f"JDFTXInfiles have conflicting values for { key } : { self [key ]} != { val } " )
94
- params [key ] = val
98
+ if key in self :
99
+ if val is params [key ]:
100
+ # Unlinking the two objects fully cannot be done by deepcopy for some reason
101
+ continue
102
+ tag_object = get_tag_object (key )
103
+ if tag_object .can_repeat :
104
+ if isinstance (val , list ):
105
+ for subval in list (val ):
106
+ # Minimum effort to avoid duplicates
107
+ if subval not in params [key ]:
108
+ params [key ].append (subval )
109
+ else :
110
+ params [key ].append (val )
111
+ else :
112
+ params [key ] = val
113
+ else :
114
+ params [key ] = val
95
115
return type (self )(params )
96
116
97
117
def as_dict (self , sort_tags : bool = True , skip_module_keys : bool = False ) -> dict :
@@ -553,6 +573,17 @@ def validate_tags(
553
573
warnmsg += "(Check earlier warnings for more details)\n "
554
574
warnings .warn (warnmsg , stacklevel = 2 )
555
575
576
+ def strip_structure_tags (self ) -> None :
577
+ """Strip all structural tags from the JDFTXInfile.
578
+
579
+ Strip all structural tags from the JDFTXInfile. This is useful for preparing a JDFTXInfile object
580
+ from a pre-existing calculation for a new structure.
581
+ """
582
+ strucural_tags = ["lattice" , "ion" , "lattice-scale" , "coords-type" ]
583
+ for tag in strucural_tags :
584
+ if tag in self :
585
+ del self [tag ]
586
+
556
587
def __setitem__ (self , key : str , value : Any ) -> None :
557
588
"""Set an item in the JDFTXInfile.
558
589
0 commit comments