Fingerprints¶
COSMolKit exposes fingerprint APIs as fixed-length bit vectors. The exposed
Morgan and MACCS branches are covered by strict RDKit bit-identical parity
tests. Similarity-shape correlation or structurally similar hashing is not a
compatibility claim. RDKFingerprintMol/topological and Avalon fingerprints
are not implemented: those calls raise an unsupported-feature error instead of
returning approximate path-hash bits. The Python Fingerprint object is a
sparse view over the binary vector: on_bits()
returns the bit indexes whose value is 1. It is not a dense floating-point
neural embedding.
Single Molecules¶
from cosmolkit import Molecule
mol = Molecule.from_smiles("c1ccccc1O")
fp = mol.fingerprint_morgan(radius=2, n_bits=2048)
print(fp.n_bits())
print(fp.on_bits())
Tanimoto similarity is computed directly on Fingerprint values:
phenol = Molecule.from_smiles("c1ccccc1O").fingerprint_morgan()
benzene = Molecule.from_smiles("c1ccccc1").fingerprint_morgan()
print(phenol.tanimoto(benzene))
Additional Output¶
fingerprint_morgan_with_output() returns a MorganFingerprintResult with
the fingerprint and experimental provenance data:
result = mol.fingerprint_morgan_with_output(radius=2, n_bits=2048)
output = result.additional_output()
print(result.fingerprint().on_bits())
print(output.atom_counts())
print(output.atom_to_bits())
print(output.bit_info_map())
print(output.atoms_per_bit())
Supported Parameters¶
The Python binding exposes the source-backed Morgan generator branches covered by exact RDKit bit parity:
radiusandn_bitsinclude_chiralityanduse_bond_typescount_simulationandcount_boundsonly_nonzero_invariantsinclude_redundant_environmentsfrom_atomsandignore_atomscustom_atom_invariantsandcustom_bond_invariantsatom_invariants_generator="connectivity" | "morgan" | "feature" | "fcfp"atom_invariants_include_ring_membershipbond_invariants_generator="morgan" | "default" | "bond"bond_invariants_use_bond_typesbond_invariants_use_chiralitynum_bits_per_feature
The list is the tested boundary, not a claim that every RDKit fingerprint generator or every input-state preparation branch is implemented. Unsupported branches propagate an error; they do not silently fall back to another fingerprint algorithm.
Batch Fingerprints¶
MoleculeBatch exposes matching batch APIs. Invalid records kept with
errors="keep" produce None in the corresponding output position.
from cosmolkit import MoleculeBatch
batch = MoleculeBatch.from_smiles_list(
["CCO", "not-smiles", "CCCO"],
errors="keep",
).with_parallel_jobs(8)
fps = batch.fingerprint_morgan_list(n_bits=2048)
print([fp.on_bits() if fp is not None else None for fp in fps])