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 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