Skip to main content

Extended cheminformatics package to work with acidic and basic groups in molecules.

Project description

ABCount logo

Introduction

ABCount is an extended cheminformatics package to work with acidic and basic groups in molecules. The tool includes the following functionalities:

  • ABCounter: SMARTS-based tool to determine the number of acidic and basic groups in molecules.
  • ABClassBuilder: Builder class that accepts a dictionary of pKa numerical values and yields an ABClassData object with their corresponding classes such as STRONG, WEAK, and NONE.

How to install the tool

ABCount can be installed from pypi (https://pypi.org/project/abcount).

pip install abcount

Usage

ABCounter

from rdkit import Chem
from abcount import ABCounter

# Use the tool out of the box with default definitions.
mol = Chem.MolFromSmiles("[nH]1nnnc1-c3c2[nH]ncc2ccc3")
abc = ABCounter()
abc.count_acid_and_bases(mol)
{'acid': 2, 'base': 2}
from rdkit import Chem
from abcount import ABCounter

# Point the tool to using your own definitions.
# The format is JSON and attributes must be consistent to those in
# acid_definitions.json and base_definitions.json in abcount/data.
mol = Chem.MolFromSmiles("[nH]1nnnc1-c3c2[nH]ncc2ccc3")
abc = ABCounter(acid_defs_filepath="/my/path/acid_defs.json", base_defs_filepath="/my/path/base_defs.json")
abc.acid_matcher.definitions_fp
PosixPath('/my/path/acid_defs.json')

ABClassBuilder and ABClassData

from abcount import ABClassBuilder

abcb = ABClassBuilder()
# The builder expects two acidic and two basic groups with these key names.
predictions = {"pka_acid1": 3.5, "pka_acid2": None, "pka_base1": 9.785, "pka_base2": None}
abcb.build(predictions)
ABClassData(acid_1_class=<AcidType.STRONG: 'strong_acid'>, acid_2_class=<AcidType.NONE: 'no_acid'>, base_1_class=<BaseType.STRONG: 'strong_base'>, base_2_class=<BaseType.NONE: 'no_base'>)
from abcount import ABClassBuilder, PKaClassBuilder

abcb = ABClassBuilder()
# Custom names can be passed but these need to be configured in a `CustomPKaAttribute` class
predictions = {"my_pka_acid1": 3.5, "my_pka_acid2": None, "my_pka_base1": 9.785, "my_pka_base2": None}
CustomPKaAttribute = PKaClassBuilder.build(ACID_1="my_pka_acid1", BASE_1="my_pka_base1", ACID_2="my_pka_acid2", BASE_2="my_pka_base2")

# The `CustomPKaAttribute` can then be passed to the builder which will map the new data to the rules
abcb.build(predictions, CustomPKaAttribute)
ABClassData(acid_1_class=<AcidType.STRONG: 'strong_acid'>, acid_2_class=<AcidType.NONE: 'no_acid'>, base_1_class=<BaseType.STRONG: 'strong_base'>, base_2_class=<BaseType.NONE: 'no_base'>)
from abcount import ABClassBuilder, PKaClassBuilder

abcb = ABClassBuilder()
# It is possible to work with fewer acidic or basic groups
# These can be set as arguments in the builder
predictions = {"pka_acid1": 3.5, "pka_base1": 9.785}
abcb.build(predictions, num_acids=1, num_bases=1)
# Note that despite passing only one group per type, the builder still returns two groups each
ABClassData(acid_1_class=<AcidType.STRONG: 'strong_acid'>, acid_2_class=None, base_1_class=<BaseType.STRONG: 'strong_base'>, base_2_class=None)

SMARTS definitions source for ABCounter

The SMARTS patterns used in this project were obtained from the following sources. Note that definitions are not deduplicated, hence require curation to avoid redundant matching.

  • Pan, X.; Wang, H.; Li, C.; Zhang, J. Z. H.; Ji, C., MolGpka: A Web Server for Small Molecule pKa Prediction Using a Graph-Convolutional Neural Network Journal of Chemical Information and Modeling 2021, 61 (7), 3159–3165. DOI: 10.1021/acs.jcim.1c00075
  • Wu, J.; Wan, Y.; Wu, Z.; Zhang, S.; Cao, D.; Hsieh, C.-Y.; Hou, T., MF-SuP-pKa: Multi-fidelity modeling with subgraph pooling mechanism for pKa prediction Acta Pharmaceutica Sinica B 2023, 13 (6). DOI: 10.26434/chemrxiv-2022-t6q61
  • Some manually curated definitions.

Some useful commands

  • Generate acidic and basic definitions from aggregated data: python abcount/_definitions.py. A follow up on how definitions can be curated will be provided.
  • Run tests: pytest -vss tests/test.py
  • Run validation: cd tests && validation.py. This will also generate four CSV files listing out false positives and negatives for the test data.

For developers

  • The package was created using uv (https://docs.astral.sh/uv/).
  • The package can be installed from the wheel in the dist/ folder. When a new version needs to be released, a new wheel must be built. That can be done by changing the version of the package inside pyproject.toml then calling uv build which will create a new build.
  • The code can be automatically tested using pytest -vss tests/test.py which requires pytest to be installed.
  • The Makefile can also be used for building (make build) or testing (make test).
  • Before committing new code, please always check that the style and syntax are compliant using pre-commit.

Setting up your development environment

The pyproject.toml already contains the optional dependencies needed for development. Follow these steps to set up the environment.

# Make sure you have got Python >= 3.10
python --version
> Python 3.12.7

# Installs `abcount` in editable mode and with dev dependencies
pip install -e .[dev]
> ...
> Successfully installed abcount ...

# Setup pre-commit hooks
pre-commit install
> pre-commit installed at .git/hooks/pre-commit

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

abcount-0.2.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

abcount-0.2.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file abcount-0.2.0.tar.gz.

File metadata

  • Download URL: abcount-0.2.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for abcount-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f5275c86089ef4bf8917fb263ac2b95c42d425ceb24df2767d760c3375a1d24c
MD5 a034e0cf60928c9f4460f2ad5ba9ac19
BLAKE2b-256 3baf85d8765755cca355868363669697158f5d1eff1c287cf2b0118defaf6729

See more details on using hashes here.

File details

Details for the file abcount-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: abcount-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for abcount-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7e845a32a45724b8fb02e93b67bef0e646d8b1a2854717ef125c2c9e9b672e7
MD5 f8ab78dc5fea94606c90b21a4464b745
BLAKE2b-256 111673a609666e2974cc0e9cfd508334562cd319b2679871ef3766931aea0ddb

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