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