AccFG: Accurate Functional Group Extraction and Molecular Structure Comparison
🚀News
-
Try AccFG in Colab.
-
(9/22/2025) AccFG v0.0.7: Fix bugs during import
-
AccFG v0.0.4: Update FG names with lowercase; Update 3 new FGs (chloroformate etc.)
-
AccFG v0.0.3:
- update
AccFG.run_mol()for directing processing rdkitMolobject - Lite version of AccFg is available through
AccFG(lite=True), this will load a simplified FG list (e.g., no primary/secondary hydroxyl but only hydroxyl)
- update
📝Introduction
This is the official code repository for the paper AccFG: Accurate Functional Group Extraction and Molecular Structure Comparison. AccFG is a tool for precise functional group (FG) extraction and molecular structure comparison.
📥Installation
We provide two methods to install AccFG:
Method 1: Installation by pip (recommended)
pip install accfg
Method 2: Installation from GitHub repository
To install AccFG, follow these steps:
- Clone/download the repository and navigate to the project directory:
git clone https://github.com/xuanliugit/AccFG.git cd AccFG
- Install the required dependencies:
conda create --name accfg python=3.10 conda activate accfg pip install -r requirements.txt # Or "pip install -e ."
Functional groups in AccFG
The FG dictionary is stored in ./accfg/fgs_common.csv and ./accfg/fgs_heterocycle.csv.
Note: The two fgs*.csv files are custom-formatted to be compatible with the AccFG.csv_to_dict() function in ./accfg/main.py. Compared to standard CSV files, they include additional annotation syntax to support structured parsing. Lines that begin with % are treated as comments to enhance readability and are excluded during data import.
⚙️Usage
Quick start:
# Get functional groups from SMILES
python run_accfg.py 'CN(C)/N=N/C1=C(NC=N1)C(=O)N'
# Compare two molecules
python run_accfg.py 'CNC(=O)Cc1nc(-c2ccccc2)cs1' --compare_smi 'CCNCCc1nc2ccccc2s1'
FG extraction
For brief results, we recommend setting
AccFG(..., lite=True). For example, lite mode combines specific hydroxyl subtypes, such as secondary OH and tertiary OH, into one general hydroxyl group.
To extract functional groups:
# example.py
from accfg import AccFG
from accfg.draw import print_fg_tree
afg = AccFG(print_load_info=True) # AccFG(print_load_info=True, lite=True) for lite version
smi = 'CN(C)/N=N/C1=C(NC=N1)C(=O)N'
fgs,fg_graph = afg.run(smi, show_atoms=True, show_graph=True)
print_fg_tree(fg_graph, fgs.keys(), show_atom_idx=True)
'''
├──Primary amide: ((10, 12, 11),)
...
'''
print(fgs)
'''
{'Primary amide': [(10, 12, 11)], 'Triazene': [(1, 3, 4)], 'imidazole': [(5, 9, 8, 7, 6)]}
'''
User-defined FGs Example:
# example.py
from accfg import AccFG
from accfg.draw import print_fg_tree
my_fgs_dict = {'Cephem': 'O=C(O)C1=CCS[C@@H]2CC(=O)N12', 'Thioguanine': 'Nc1nc(=S)c2[nH]cnc2[nH]1'}
my_afg = AccFG(user_defined_fgs=my_fgs_dict,print_load_info=True)
cephalosporin_C = 'CC(=O)OCC1=C(N2[C@@H]([C@@H](C2=O)NC(=O)CCC[C@H](C(=O)O)N)SC1)C(=O)O'
fgs,fg_graph = my_afg.run(cephalosporin_C, show_atoms=True, show_graph=True)
print_fg_tree(fg_graph, fgs.keys(), show_atom_idx=True) # This will print the FG tree
'''
├──Primary aliphatic amine: ((21,),)
├──...
'''
To print functional groups:
print(fgs) # Show top level FGs
'''
{'Primary aliphatic amine': [(21,)],
'Carboxylic acid': [(22, 23, 24)],
'Carboxylic ester': [(1, 2, 3, 4)],
'Secondary amide': [(15, 16, 14, 13)],
'Cephem': [(8, 7, 9, 6, 5, 27, 26, 25, 13, 11, 12, 10)]}
'''
FG extraction visualization
from accfg.draw import draw_mol_with_fgs, molimg
molimg(draw_mol_with_fgs(cephalosporin_C, afg=my_afg, img_size=(900,900)))
This will show image with FGs highlighted
Molecular structure comparison
from accfg import AccFG, compare_mols
from accfg.draw import draw_compare_mols, draw_RascalMCES, img_grid
smi_1,smi_2 = ('CNC(=O)Cc1nc(-c2ccccc2)cs1','CCNCCc1nc2ccccc2s1')
diff = compare_mols(smi_1, smi_2)
print(diff) # This print the structure difference
'''
(([('Secondary amide', 1, [(2, 3, 1)]),
...
'''
draw_RascalMCES(smi_1, smi_2) # This draw the RascalMCES comparison
Molecular structure comparison visualization
img = img_grid(draw_compare_mols(smi_1, smi_2),num_columns=2)
with open('results/compare_mols.png', 'wb') as f:
img.save(f, format='PNG')
img
Advanced usage
You can customize which functional group definitions are loaded when creating an AccFG instance:
from accfg import AccFG
afg = AccFG(
common_fgs=True,
heterocycle_fgs=True,
user_defined_fgs={},
print_load_info=False,
lite=False,
exclude_fgs=None,
)
| Argument | Default value | Description |
|---|---|---|
common_fgs |
True |
Load the built-in common functional group definitions from accfg/fgs_common.csv. |
heterocycle_fgs |
True |
Load the built-in heterocycle functional group definitions from accfg/fgs_heterocycle.csv. |
user_defined_fgs |
{} |
Add custom functional groups as {name: SMILES_or_SMARTS}. These are merged with the built-in definitions. |
print_load_info |
False |
Print how many functional groups were loaded when the instance is created. |
lite |
False |
Use the simplified common functional group list by skipping entries marked for the full version. |
exclude_fgs |
None |
Exclude functional groups by name, for example ['hydroxy']. Use ['rings'] to disable heterocycle functional groups and exclude benzene. |
afg = AccFG(exclude_fgs=['rings'])
⚒️Run
To run the BBBP dataset, Lipophilicity dataset, BACE dataset, and CHEMBL drugs, simply run:
python run_data.py
The result is in ./molecule_data. The code to process the data is in exam_data.py
All other examples in the manuscript are in example.ipynb.
Cite this work
@article{liu2025accfg,
title={AccFG: Accurate Functional Group Extraction and Molecular Structure Comparison},
author={Liu, Xuan and Swaminathan, Sarathkrishna and Zubarev, Dmitry and Ransom, Brandi and Park, Nathaniel and Schmidt, Kristin and Zhao, Huimin},
journal={Journal of Chemical Information and Modeling},
volume={65},
number={16},
pages={8593--8602},
year={2025},
publisher={ACS Publications}
}
Metadata
Release files for accfg 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| accfg-0.1.0.tar.gz | 25.2 kB | Without provenance | Details for accfg-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| accfg-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for accfg-0.1.0-py3-none-any.whl |
Total release size: 47.4 kB
Release files / accfg-0.1.0.tar.gz
| Download URL | accfg-0.1.0.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5561a51f7d1730a04305b4d749cbdd2735146b14a77f80b97a7b1c9a9a0a26f5
|
|
BLAKE2b-256 checksum How to use checksums |
87344cbc570961d2f61d971050f74a24e35e9fc34f2631f5f1b21dde76047e80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / accfg-0.1.0-py3-none-any.whl
| Download URL | accfg-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d07b2bb963ede64c2733b923b6d5a1598d14d201e05575b9c8e1bb750667b66
|
|
BLAKE2b-256 checksum How to use checksums |
60093109bad946944d979893c71b95e46a046484a83ddc3d6e468463f99a7459
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Security for accfg 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.