Skip to main content

Generate molecular fingerprints with guaranteed collision‑free bits.

Project description

bit_collision_free_MF

A Python package for generating molecular fingerprints without bit collisions.

Description

bit_collision_free_MF generates count-based Morgan fingerprints while eliminating bit collisions, which can significantly improve the accuracy and reliability of molecular fingerprints in cheminformatics applications. The package automatically determines the optimal fingerprint length to ensure that each structural feature maps to a unique bit in the fingerprint.

Collision detection is based on comparing Morgan invariants (unique substructure identifiers), which catches all collision types — including collisions between different substructures at the same radius. This works reliably for all radius values, including radius=0.

Installation

Requirements

  • Python 3.9 or higher
  • numpy
  • pandas
  • rdkit

Simple Installation

pip install -U bit_collision_free_MF

This will automatically install all dependencies, including RDKit.

Manual Installation

# Install dependencies
pip install numpy pandas rdkit

# Install the package
pip install -U bit_collision_free_MF

For development installation:

git clone https://github.com/Shifa-Zhong/bit_collision_free_MF.git
cd bit_collision_free_MF
pip install -e .

Features

  • Invariant-based collision detection: compares actual substructure identifiers, not just radii, to guarantee truly collision-free fingerprints
  • Count-based output: generates count fingerprints (not binary), preserving substructure frequency information
  • Automatically determines the optimal fingerprint length using exponential growth + binary search
  • Supports all radius values including radius=0
  • Consistent zero-column removal: columns identified during fit() are reused in transform(), ensuring train/test dimensionality alignment
  • Feature names (fp_0, fp_1, ...) are 0-indexed to match bit positions in RDKit's bitInfo, enabling correct substructure interpretation
  • Easy CSV export with customizable headers
  • Seamless integration with pandas and NumPy

Usage

Basic Usage

from bit_collision_free_MF import generate_fingerprints, save_fingerprints
import pandas as pd

# Load your data
data = pd.read_csv('your_molecules.csv')

# Generate fingerprints
fingerprints, fp_generator = generate_fingerprints(
    data,
    smiles_column='smiles',
    radius=1,
    remove_zero_columns=True
)

# Save fingerprints to CSV
save_fingerprints(
    fingerprints,
    fp_generator,
    output_path='path/to/output.csv',
    include_header=True
)

Using the CollisionFreeMorganFP Class Directly

from bit_collision_free_MF import CollisionFreeMorganFP
import pandas as pd

# Load your data
data = pd.read_csv('your_molecules.csv')
smiles_list = data['smiles'].tolist()

# Create and fit the fingerprint generator
fp_generator = CollisionFreeMorganFP(radius=1)
fp_generator.fit(smiles_list, remove_zero_columns=True)

# Generate fingerprints
fingerprints = fp_generator.transform(smiles_list)

# Get feature names (fp_0, fp_1, ... aligned with bit indices)
feature_names = fp_generator.get_feature_names()

# Create a DataFrame with the fingerprints
result_df = pd.DataFrame(fingerprints, columns=feature_names)
result_df.to_csv('fingerprints.csv', index=False)

Train/Test Split with Consistent Dimensions

from bit_collision_free_MF import CollisionFreeMorganFP

# fit() on training set records which columns are all-zero
fp_gen = CollisionFreeMorganFP(radius=1)
fp_gen.fit(train_smiles, remove_zero_columns=True)

# transform() reuses the same zero-column mask for both sets
X_train = fp_gen.transform(train_smiles)
X_test = fp_gen.transform(test_smiles)
# X_train.shape[1] == X_test.shape[1] guaranteed

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For academic inquiries or collaboration, please contact:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bit_collision_free_mf-0.9.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bit_collision_free_mf-0.9.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file bit_collision_free_mf-0.9.2.tar.gz.

File metadata

  • Download URL: bit_collision_free_mf-0.9.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for bit_collision_free_mf-0.9.2.tar.gz
Algorithm Hash digest
SHA256 7f15168a6467145fb3ac47026a26c9c8547e42b6dce484e2466905f58bb1b4b6
MD5 a1e8a5585b84f7e3a9c7d909f904e574
BLAKE2b-256 58895435fbe16c7df412757c41bf87fdf939e2208053e18f561e7a9fb6d203e1

See more details on using hashes here.

File details

Details for the file bit_collision_free_mf-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for bit_collision_free_mf-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 32476dac019f752eb4d687a6c9d1195d75adad75cbedb50c26bafb13a779dec1
MD5 0a8473affb28fdac32a63a2736a325a4
BLAKE2b-256 130362304aadd0a6f9c86a0c617649aac3c336f93a0b5b88e98075d9d78c324e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page