@@ -46,6 +46,10 @@ class is written.
4646
4747# TODO: Add check for whether all ions have or lack velocities.
4848# 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.
4953
5054
5155class JDFTXInfile (dict , MSONable ):
@@ -80,18 +84,34 @@ def __add__(self, other: JDFTXInfile) -> JDFTXInfile:
8084 """Add existing JDFTXInfile object to method caller JDFTXInfile object.
8185
8286 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.
8388
8489 Args:
8590 other (JDFTXInfile): JDFTXInfile object to add to the method caller object.
8691
8792 Returns:
8893 JDFTXInfile: The combined JDFTXInfile object.
8994 """
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 ()))
9197 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
95115 return type (self )(params )
96116
97117 def as_dict (self , sort_tags : bool = True , skip_module_keys : bool = False ) -> dict :
@@ -553,6 +573,17 @@ def validate_tags(
553573 warnmsg += "(Check earlier warnings for more details)\n "
554574 warnings .warn (warnmsg , stacklevel = 2 )
555575
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+
556587 def __setitem__ (self , key : str , value : Any ) -> None :
557588 """Set an item in the JDFTXInfile.
558589
0 commit comments