def read(self, filename, format='auto'): """Load structure from a file, any original data become lost. filename -- file to be loaded format -- all structure formats are defined in Parsers submodule, when format == 'auto' all Parsers are tried one by one Return instance of data Parser used to process file. This can be inspected for information related to particular format. """ import diffpy.Structure import diffpy.Structure.Parsers getParser = diffpy.Structure.Parsers.getParser p = getParser(format) new_structure = p.parseFile(filename) # reinitialize data after successful parsing # avoid calling __init__ from a derived class Structure.__init__(self) if new_structure is not None: self.__dict__.update(new_structure.__dict__) self[:] = new_structure if not self.title: import os.path tailname = os.path.basename(filename) tailbase = os.path.splitext(tailname)[0] self.title = tailbase return p
def testWriter(self): p = getParser() from diffpy import Structure as matter a = 1.5 lattice = matter.Lattice(2*a, 2*a, 2*a, 90,90,90) atoms = [matter.Atom('Ni'), matter.Atom('Ni', (0.5,0.5,0.5))] struct = Structure(lattice=lattice, atoms=atoms) #, sgid=229) print('original unitcell, cartesian coords') print('\n'.join(p.toLines(struct))) print('original unitcell, fractional coords') print('\n'.join(p.toLines(struct, use_fractional_coordinates=1, latticeAsDescription=1))) # print 'primitive unitcell, cartesian coords' # print '\n'.join(p.toLines(struct, use_primitive_unitcell=1)) # print 'primitive unitcell, fractional coords' # print '\n'.join(p.toLines(struct, use_primitive_unitcell=1, use_fractional_coordinates=1)) return
def __copy__(self, target=None): '''Create a deep copy of this instance. target -- optional target instance for copying, useful for copying a derived class. Defaults to new instance of the same type as self. Return a duplicate instance of this object. ''' if target is None: target = Structure() elif target is self: return target # copy attributes as appropriate: target.title = self.title target.lattice = Lattice(self.lattice) target.pdffit = copy.deepcopy(self.pdffit) # copy all atoms to the target target[:] = self return target
def readStr(self, s, format='auto'): """Load structure from a string, any original data become lost. s -- string with structure definition format -- all structure formats are defined in Parsers submodule, when format == 'auto' all Parsers are tried one by one Return instance of data Parser used to process input string. This can be inspected for information related to particular format. """ from diffpy.Structure.Parsers import getParser p = getParser(format) new_structure = p.parse(s) # reinitialize data after successful parsing # avoid calling __init__ from a derived class Structure.__init__(self) if new_structure is not None: self.__dict__.update(new_structure.__dict__) self[:] = new_structure return p
def __emptySharedStructure(self): '''Return empty Structure with standard attributes same as in self. ''' rv = Structure() rv.__dict__.update([(k, getattr(self, k)) for k in rv.__dict__]) return rv