chemfp.fpb_io module

I/O routines for the FPB format.

This is an internal chemfp module. It should not be imported by programs which use the public API. (Let me know if anything else should be part of the public API.)

This module contains class definitions for a few objects which are returned as part of the public API. The FPBError exception is raised if an input file is not in FPB format. The function chemfp.open_fingerprint_writer() returns an OrderedFPBWriter or InputOrderFPBWriter instance to write an FPB file when using reorder=True and reorder=False, respectively.

exception chemfp.fpb_io.FPBError

Bases: chemfp.ChemFPError

Exception raised when the input file does not appear to be in FPB format

class chemfp.fpb_io.OrderedFPBWriter(output, metadata=None, alignment=8, include_popc=True, include_hash=True, max_spool_size=None, tmpdir=None, close=None, location=None)

Bases: chemfp.FingerprintWriter

Fingerprint writer for FPB files where the input fingerprint order is preserved

This is a subclass of chemfp.FingerprintWriter.

Instances have the following public attributes:

metadata

a chemfp.Metadata instance

closed

False when the file is open, else True

Other attributes (like “alignment”, “include_hash”, “include_popc”, “max_spool_size”, and “tmpdir”) are undocumented and subject to change in the future. Let me know if they are useful.

An OrderedFPBWriter is also is own context manager, and will close the writer on context exit.

close()

Close the output writer

format = 'fpb'
write_fingerprint(id, fp)

Write a single fingerprint record with the given id and fp to the destination

Parameters:
  • id (string) – the record identifier
  • fp (bytes) – the fingerprint
write_fingerprints(id_fp_iter)

Write a sequence of (id, fingerprint) pairs to the destination

Parameters:id_fp_pairs – An iterable of (id, fingerprint) pairs.
class chemfp.fpb_io.InputOrderFPBWriter(output, metadata=None, alignment=8, include_popc=True, include_hash=True, max_spool_size=None, num_entries=None, tmpdir=None, close=None, location=None)

Bases: chemfp.FingerprintWriter

Fingerprint writer for FPB files which preserves the input fingerprint order

This is a subclass of chemfp.FingerprintWriter.

Instances have the following public attributes:

metadata

a chemfp.Metadata instance

closed

False when the file is open, else True

Other attributes (like “alignment”, “include_hash”, “include_popc”, “max_spool_size”, and “tmpdir”) are undocumented and subject to change in the future. Let me know if they are useful.

An InputOrderFPBWriter is also is own context manager, and will close the writer on context exit.

close()

Close the output writer

This will set self.closed to False

format = 'fpb'
write_fingerprint(id, fp)

Write a single fingerprint record with the given id and fp to the destination

Parameters:
  • id (string) – the record identifier
  • fp (bytes) – the fingerprint
write_fingerprints(id_fp_iter)

Write a sequence of (id, fingerprint) pairs to the destination

Parameters:id_fp_pairs – An iterable of (id, fingerprint) pairs.