Package schrodinger :: Module structure :: Class MultiFileStructureReader
[hide private]
[frames] | no frames]

Class MultiFileStructureReader

                 object --+    
                          |    
_ReaderWriterContextManager --+
                              |
                             MultiFileStructureReader

Provides a single iterator that reads structure from multiple files. Typical usage is idential to typical useage of the StructureReader class except that the class is instantiated with a python list of file names rather than a single file name.

By default, the StructureReader class is used to read the files, but this is customizable with the reacer_class keyword.

API Example:

   names = ['file1.mae', 'file2.mae', 'file3.pdb']
   reader = MultiFileStructureReader(names)
   first_struct = reader.next()
   for struct in reader:
       do stuff

By default, the reader skips files that raise Exceptions and stores the list of skipped files in the failed_files property.

The current StructureReader can be accessed with the reader property

Instance Methods [hide private]
 
__init__(self, files, *args, **kwargs)
Create a MultiFileStructureReader
 
__iter__(self)
Required to make the class an iterator
 
_createNewReader(self)
Create a file reader for the next file.
 
next(self)
Get the next structure to process.

Inherited from _ReaderWriterContextManager: __enter__, __exit__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  reader_class
The class used to read files
  pass_errors
False if exceptions should be raised, True if they should be caught
  files
List of files remaining to be read
  current_filename
The file currently being read
  index_in_current_file
Index of current structure in current file
  failed_files
List of (failed_file_name, error_message)
  reader
Current file reader
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, files, *args, **kwargs)
(Constructor)

 

Create a MultiFileStructureReader

Parameters:
  • files (list) - A list of paths to files to be read
  • reader_class (Reader class) - By default, StructureReader is used to read the files. A more specific class can be provided, such as PDBReader
  • pass_errors (bool) - If True, any filename that raises an expected exception will be skipped. Skipped filenames are stored in the failed_files property and can be retrieved after reading. Items of the failed_files list are tuples (filename, error_message). Expected Exceptions include: IOError (does not exist, or unreadable), ValueError (unknown extension), MmException (error opening file) or an Exception while reading structures. The default of False will cause the exceptions to be raise'd.

    Any additional parameters and keyword arguments are passed to the structure reader class.

Overrides: object.__init__

_createNewReader(self)

 

Create a file reader for the next file. Sets self.reader = None if there are no more files to be read.

next(self)

 

Get the next structure to process. This might either be the next structure in the currently open file, or might result in the next file being opened.

Raises:
  • StopIteration - When all structures in all files have been read