consistent copy functionality
This commit is contained in:
parent
6fe1ff8e39
commit
35ca1ffb0a
|
@ -1,3 +1,4 @@
|
|||
import copy
|
||||
from io import StringIO
|
||||
import abc
|
||||
|
||||
|
@ -35,6 +36,14 @@ class Config(dict):
|
|||
output.seek(0)
|
||||
return ''.join(output.readlines())
|
||||
|
||||
|
||||
def __copy__(self):
|
||||
"""Create deep copy."""
|
||||
return copy.deepcopy(self)
|
||||
|
||||
copy = __copy__
|
||||
|
||||
|
||||
@classmethod
|
||||
def load(cls,fname):
|
||||
"""
|
||||
|
@ -52,6 +61,7 @@ class Config(dict):
|
|||
fhandle = fname
|
||||
return cls(yaml.safe_load(fhandle))
|
||||
|
||||
|
||||
def save(self,fname,**kwargs):
|
||||
"""
|
||||
Save to yaml file.
|
||||
|
@ -95,6 +105,7 @@ class Config(dict):
|
|||
"""Check for completeness."""
|
||||
pass
|
||||
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def is_valid(self):
|
||||
|
|
|
@ -204,7 +204,7 @@ class ConfigMaterial(Config):
|
|||
Limit renaming to selected constituents.
|
||||
|
||||
"""
|
||||
dup = copy.deepcopy(self)
|
||||
dup = self.copy()
|
||||
for i,m in enumerate(dup['material']):
|
||||
if ID and i not in ID: continue
|
||||
for c in m['constituents']:
|
||||
|
@ -228,7 +228,7 @@ class ConfigMaterial(Config):
|
|||
Limit renaming to selected homogenization IDs.
|
||||
|
||||
"""
|
||||
dup = copy.deepcopy(self)
|
||||
dup = self.copy()
|
||||
for i,m in enumerate(dup['material']):
|
||||
if ID and i not in ID: continue
|
||||
try:
|
||||
|
|
|
@ -57,13 +57,10 @@ class Grid:
|
|||
|
||||
|
||||
def __copy__(self):
|
||||
"""Copy grid."""
|
||||
"""Create deep copy."""
|
||||
return copy.deepcopy(self)
|
||||
|
||||
|
||||
def copy(self):
|
||||
"""Copy grid."""
|
||||
return self.__copy__()
|
||||
copy = __copy__
|
||||
|
||||
|
||||
def diff(self,other):
|
||||
|
|
|
@ -199,7 +199,7 @@ class Orientation(Rotation):
|
|||
|
||||
|
||||
def __copy__(self,**kwargs):
|
||||
"""Copy."""
|
||||
"""Create deep copy."""
|
||||
return self.__class__(rotation=kwargs['rotation'] if 'rotation' in kwargs else self.quaternion,
|
||||
lattice =kwargs['lattice'] if 'lattice' in kwargs else self.lattice
|
||||
if self.lattice is not None else self.family,
|
||||
|
|
|
@ -78,9 +78,8 @@ class Rotation:
|
|||
])
|
||||
|
||||
|
||||
# ToDo: Check difference __copy__ vs __deepcopy__
|
||||
def __copy__(self,**kwargs):
|
||||
"""Copy."""
|
||||
"""Create deep copy."""
|
||||
return self.__class__(rotation=kwargs['rotation'] if 'rotation' in kwargs else self.quaternion)
|
||||
|
||||
copy = __copy__
|
||||
|
|
|
@ -42,12 +42,10 @@ class Table:
|
|||
return len(self.data)
|
||||
|
||||
def __copy__(self):
|
||||
"""Copy Table."""
|
||||
"""Create deep copy."""
|
||||
return copy.deepcopy(self)
|
||||
|
||||
def copy(self):
|
||||
"""Copy Table."""
|
||||
return self.__copy__()
|
||||
copy = __copy__
|
||||
|
||||
|
||||
def _label_discrete(self):
|
||||
|
|
Loading…
Reference in New Issue