This package contains utilities to read, write a variety of chemical file formats.
Initialize the appropriate IOHandler for a given file extension or file format.
The datafile function can be conveniently used to quickly read or write data in a certain format:
>>> handler = datafile("molecule.pdb")
>>> mol = handler.read("molecule")
# You can also use this shortcut
>>> mol = datafile("molecule.pdb").read("molecule")
Parameters
Generic base class for file readers and writers.
The initialization function takes a file-like object fd, as an argument.
Subclasses can extend the methods __init__, read and write to implement their reading and writing routines.
Attributes
Type : | list of str |
---|
A list of features that the handler can read.
Type : | list of str |
---|
A list of features that IOHandler can write.
Check if the feature is supported in the handler and raise an exception otherwise.
Parameters
Read and return the feature feature. It should raise an ValueError if the feature is not present in the handler can_read attribute, use the method IOHandler.check_feature() to provide this behaviour.
Certain features may require additional arguments, and it is possible to pass those as well.
Example
Subclasses can reimplement this method to add functionality:
class XyzIO(IOHandler):
can_read = ['molecule']
def read(self, feature, *args, **kwargs):
self.check_feature(feature, "read")
if feature == 'molecule':
# Do stuff
return geom
Same as read(). You have to pass also a value to write and you may pass any additional arguments.
Example
class XyzIO(IOHandler):
can_write = ['molecule']
def write(self, feature, value, *args, **kwargs):
self.check_feature(feature, "write")
if feature == 'molecule':
# Do stuff
return geom