oemolistream

class oemolistream : public oemolstreambase

The oemolistream class provides a stream-like abstraction for reading molecules from files, strings or standard input. The oemolistream maintains the format and flavor of molecular reading for the stream. It also manages the conversion between multi-conformer molecules and single conformer molecules in cases where the molecule read into is not compatible with the file format (in the sense of a multi-conformer file format being read into a single-conformer molecule, or a single-conformer file format being read into a multi-conformer molecule). The oemolistream is capable of uncompressing gzip files while reading.

The following methods are publicly inherited from oemolstreambase:

ClearCSVHeader

GetFlavor

SetFormat

GetBinaryIOHandler

GetFormat

close

GetCSVHeader

Getgz

open

GetFileName

SetFlavor

Constructors

oemolistream() -> oemolistream

Default constructor. Creates a new oemolistream object that is connected to the standard input.

oemolistream(arg2: str) -> oemolistream
oemolistream(fn: str) -> oemolistream

Creates a new oemolistream object and opens the file specified by the given name (‘fname’).

oemolistream(arg2: oeistream, owned: bool = True) -> oemolistream

Creates a new oemolistream object from an existing oeistream object. The second optional argument is used to indicate whether the new oemolistream now owns the given oeistream and is therefore responsible for closing and destroying it when it itself is closed and/or destroyed.

Warning

Only in C++ can an oemolistream object own an existing oeistream object.

Usage in Python

i = oechem.oeistream()
owned = True
ifs = oechem.oemolistream(i, not owned)

See also

To associate a file or a stream with an oemolistream after it has been created, see the oemolstreambase.open method.

operator bool

IsValid() -> bool

GetConfTest

GetConfTest() -> OEConfTestBase

GetOEMols

GetOEMols() -> <generator of OEMol objects>

Returns a generator over all the molecules in the file or stream. Each molecule will be an OEMol object. These are references to the molecules in the file or stream and so calling this method does not create copies of the molecules.

GetOEGraphMols

GetOEGraphMols() -> <generator of OEGraphMol objects>

Returns a generator over all the molecules in the input stream in the current order. Each molecule will be an OEGraphMol object. If opened on a multi-conformer .oeb file, only the first conformer will be returned for each molecule record.

Note

Unlike OEChem::OEMolDatabase::GetOEGraphMols, a reference to each molecule will be used for each iteration to avoid unnecessary copying of molecules.

GetMCMolBases

GetMCMolBases(single: bool = False) -> Iterable[OEMol]

GetMolBases

GetMolBases() -> Iterable[Union[OEGraphMol, OEMol, OEQMol]]

GetReadFailureCt

GetReadFailureCt() -> int

IncrementReadFailureCt

IncrementReadFailureCt() -> None

ResetReadFailureCt

ResetReadFailureCt() -> None

SetConfTest

SetConfTest(arg2: OEConfTestBase) -> bool

Sets the functor class which is used to compare incoming graphs to determine whether they should be placed as conformers of a multi-conformer molecule or be returned individually as single molecules. The default conformer test never places separate graphs into a multi-conformer molecule (OEDefaultConfTest).

SetFlavor

SetFlavor(format: int, flavor: int) -> bool

Sets the file flavor for a given format associated with the oemolistream object. The set of valid formats are defined in the the OEFormat namespace. The set of valid bitmasks flavors are defined in the OEIFlavor namespace. The current flavor can be queried using the oemolstreambase.GetFlavor method. Each format has its own specific flavor which must be set separately. The oemolistream constructors call the OESetDefaultFlavors function to set the flavors for all of the formats to their default state.

SetFormat

SetFormat(format: int) -> bool

Sets the file format associated with the oemolistream object. The set of valid formats are defined in the the OEFormat namespace. By default, when reading from standard input, the associated file format is OEFormat_SMI. The file format property of an oemolistream may be retrieved using the oemolstreambase.GetFormat method.

Note

The file format property is also set automatically by oemolstreambase.open based upon the file extension of the specified filename.

SetTracer

SetTracer(tracer: OETracerBase, owntracer: bool) -> bool

Registers the tracer, tracer, to report the current progress of the oemolistream object on reading molecules. The second optional argument is used to indicate whether the oemolistream now owns the given OETracerBase object and is therefore responsible for closing and destroying it when it itself is closed and/or destroyed.

Warning

Only in C++ can an oemolistream object own an existing OETracerBase object.

See also

Setgz

Setgz(gz: bool, sptr: oeistream = None, owned: bool = False) -> bool

Specifies that the contents of the oemolistream object are to be treated as compressed by GNU gzip compressed. The decompression takes place on-the-fly. Usually the ‘gz’ property of a oemolistream object is determined implicitly from the file extension used to open the stream for reading. The current ‘gz’ property of the oemolistream object can be retrieved using the oemolstreambase.Getgz method.

close

close() -> None

Closes the oemolistream object. This method may be safely called multiple times. However oemolistream.close method is called from within the oemolistream destructor and therefore it is not necessary to call this explicitly under most circumstances.

eof

eof() -> bool

getbyte

getbyte() -> int

getline

getline(buffer: str, max: oesize_t) -> bool

openstring

bool openstring(const std::string& str)
bool openstring(const unsigned char* buffer, oesize_t len)

Allows the oemolistream to read from a buffer in memory, instead of from a file or standard input.

Internally, the oemolistream.openstring method make a copy of the specified file contents, allowing the oemolistream to continue to function independently of whether the original buffer is later modified or deallocated.

Note

Prior to calling oemolistream.openstring it is necessary to specify the format and whether or not the format is compressed with gzip. These can be set with the oemolistream.SetFormat and oemolistream.Setgz methods respectively.

peekbyte

peekbyte() -> int

read

read(buffer: str, len: oesize_t) -> bool

rewind

rewind() -> None

seek

seek(pos: oefpos_t) -> None

Moves the position of the next valid read to the position indicated. This function takes account of gzip streams and molecule caching.

size

size() -> oefpos_t

Returns the size of the input stream if applicable to the current stream. The return type is a portable file-system pointer type.

skip

skip(len: oefpos_t) -> bool

skipbyte

skipbyte() -> bool

skipline

skipline() -> bool

tell

tell() -> oefpos_t

Returns the current position of the next read. This function accounts for molecular caching.

Note

If you are reading an .oeb file that was written as multi-conformer molecules and is being read with single conformer molecules, all of the conformers are read into cache at once, and the pointer will point to the beginning of a multi-conformer molecule rather than to a conformer inside a molecule.