code: def modify_object(self, modification, obj):
          
          d = obj.as_dict()
          self.modify(modification, d)
          return obj.from_dict(d)
docs: Modify an object that supports pymatgen's as_dict() and from_dict API.
  
          Args:
              modification (dict): Modification must be {action_keyword :
                  settings}. E.g., {'_set': {'Hello':'Universe', 'Bye': 'World'}}
              obj (object): Object to modify