# RDF READER
[](https://coveralls.io/github/ChemAILtd/rdfreader)
[](https://results.pre-commit.ci/latest/github/ChemAILtd/rdfreader/main)
[](https://github.com/ChemAILtd/rdfreader/actions?workflow=test)
[](https://github.com/ChemAILtd/rdfreader/blob/master/LICENSE.txt)
[](https://github.com/python/black)
[](https://pypi.python.org/pypi/rdfreader/)
## User Guide
### Installation
``` bash
pip install rdfreader
```
### Basic Usage
``` python
from rdfreader import RDFParser
rdf_file_name = "reactions.rdf"
with open(rdf_file_name, "r") as rdf_file:
# create a RDFParser object, this is a generator that yields Reaction objects
rdfreader = RDFParser(
rdf_file,
except_on_invalid_molecule=False, # will return None instead of raising an exception if a molecule is invalid
except_on_invalid_reaction=False, # will return None instead of raising an exception if a reaction is invalid
)
for rxn in rdfreader:
if rxn is None:
continue # the parser failed to read the reaction, go to the next one
# rxn is a Reaction object, it is several attributes, including:
print(rxn.smiles) # reaction SMILES string
print(rxn.properties) # a dictionary of properties extracted from the RXN record
reactants = rxn.reactants # a list of Molecule objects
products = rxn.products
solvents = rxn.solvents
catalysts = rxn.catalysts
# Molecule objects have several attributes, including:
print(reactants[0].smiles)
print(reactants[0].properties) # a dictionary of properties extracted from the MOL record (often empty)
reactants[0].rd_mol # an RDKit molecule object
```
### Example Data
You can find example data in the `test/resources directory`. `spresi-100.rdf` contains 100 example records from SPRESI.
### Important Note Regarding File Formats
If you are using files that have been saved with Windows-style carriage returns (`^M^M`, or `\r\r`), you may encounter issues when running this package.
To correct this issue, you can use the following `sed` command in a Linux-based terminal to convert double carriage returns to single ones in affected files:
```bash
sed -i 's/\r\r/\r/g' reactions.rdf
```
## Developer Guide
The project is managed and packaged using [poetry](https://python-poetry.org/docs/#installation).
### Installation
``` bash
git clone https://github.com/ChemAILtd/rdfreader.git
poetry install # create a virtual environment and install the project dependencies
pre-commit install # install pre-commit hooks, these mostly manage codestyle
```
### Contributions
Contributions are welcome via the [fork and pull request model](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
Before you commit changes, ensure these pass the hooks installed by pre-commit. This should be run automatically on each commit if you have run `pre-commit install`, but can be run manually from the terminal with `pre-commit run`.
### Releases
Releases are managed by GitHub releases/workflow. The version number in the pyproject file should ideally be kept up to date to the current release but is ignored by the release workflow.
To release a new version:
- Update the pyproject.toml version number.
- Push the changes to GitHub and merge to main via a pull request.
- Use the github website to create a release. Tag the commit to be released with a version number, e.g. v1.2.3. The tag should be in v*.*.* and match the version number in the pyproject.toml file.
- When the release is published, a github workflow will run, build a wheel and publish it to PyPI.
Raw data
{
"_id": null,
"home_page": "https://chemai.io",
"name": "rdfreader",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "chemistry, rdkit, rdf, rxn, mol, reaction, molecule, reader, parser, chemai, ctab, cheminformatics",
"author": "ChemAI Ltd.",
"author_email": "enquiries@chemai.io",
"download_url": "https://files.pythonhosted.org/packages/20/f8/85a448b17a4c48c6b0c5e7fdf1f433652960d21f50b0839808ffb855de5e/rdfreader-1.0.3.tar.gz",
"platform": null,
"description": "# RDF READER\n\n[](https://coveralls.io/github/ChemAILtd/rdfreader)\n[](https://results.pre-commit.ci/latest/github/ChemAILtd/rdfreader/main)\n[](https://github.com/ChemAILtd/rdfreader/actions?workflow=test)\n[](https://github.com/ChemAILtd/rdfreader/blob/master/LICENSE.txt)\n[](https://github.com/python/black)\n[](https://pypi.python.org/pypi/rdfreader/)\n\n## User Guide\n\n### Installation\n\n``` bash\npip install rdfreader\n```\n\n### Basic Usage\n\n``` python\nfrom rdfreader import RDFParser\n\nrdf_file_name = \"reactions.rdf\"\n\nwith open(rdf_file_name, \"r\") as rdf_file:\n\n # create a RDFParser object, this is a generator that yields Reaction objects\n rdfreader = RDFParser(\n rdf_file,\n except_on_invalid_molecule=False, # will return None instead of raising an exception if a molecule is invalid\n except_on_invalid_reaction=False, # will return None instead of raising an exception if a reaction is invalid\n )\n\n for rxn in rdfreader:\n if rxn is None:\n continue # the parser failed to read the reaction, go to the next one\n\n # rxn is a Reaction object, it is several attributes, including:\n print(rxn.smiles) # reaction SMILES string\n print(rxn.properties) # a dictionary of properties extracted from the RXN record\n\n reactants = rxn.reactants # a list of Molecule objects\n products = rxn.products\n solvents = rxn.solvents\n catalysts = rxn.catalysts\n\n # Molecule objects have several attributes, including:\n print(reactants[0].smiles)\n print(reactants[0].properties) # a dictionary of properties extracted from the MOL record (often empty)\n reactants[0].rd_mol # an RDKit molecule object\n```\n\n### Example Data\n\nYou can find example data in the `test/resources directory`. `spresi-100.rdf` contains 100 example records from SPRESI.\n\n### Important Note Regarding File Formats\n\nIf you are using files that have been saved with Windows-style carriage returns (`^M^M`, or `\\r\\r`), you may encounter issues when running this package.\n\nTo correct this issue, you can use the following `sed` command in a Linux-based terminal to convert double carriage returns to single ones in affected files:\n\n```bash\nsed -i 's/\\r\\r/\\r/g' reactions.rdf\n```\n\n## Developer Guide\n\nThe project is managed and packaged using [poetry](https://python-poetry.org/docs/#installation).\n\n### Installation\n\n``` bash\ngit clone https://github.com/ChemAILtd/rdfreader.git\npoetry install # create a virtual environment and install the project dependencies\npre-commit install # install pre-commit hooks, these mostly manage codestyle\n```\n\n### Contributions\n\nContributions are welcome via the [fork and pull request model](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).\n\nBefore you commit changes, ensure these pass the hooks installed by pre-commit. This should be run automatically on each commit if you have run `pre-commit install`, but can be run manually from the terminal with `pre-commit run`.\n\n### Releases\n\nReleases are managed by GitHub releases/workflow. The version number in the pyproject file should ideally be kept up to date to the current release but is ignored by the release workflow.\n\nTo release a new version:\n\n- Update the pyproject.toml version number.\n- Push the changes to GitHub and merge to main via a pull request.\n- Use the github website to create a release. Tag the commit to be released with a version number, e.g. v1.2.3. The tag should be in v*.*.* and match the version number in the pyproject.toml file.\n- When the release is published, a github workflow will run, build a wheel and publish it to PyPI.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Read the full contents of CTAB .rdf files in python. Captures RXN and MOL record using RDKit and reads additional data fields (including solvents/catalysts/agents).",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://chemai.io",
"Repository": "https://github.com/ChemAILtd/rdfreader/"
},
"split_keywords": [
"chemistry",
" rdkit",
" rdf",
" rxn",
" mol",
" reaction",
" molecule",
" reader",
" parser",
" chemai",
" ctab",
" cheminformatics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c455b52cea0602e8c67a07ba95a675c1b6c5550975dc91a1e5efc605f17bc76b",
"md5": "b5b009ce63e8faff6c44593ff23dbbe0",
"sha256": "f08431bc93d63c2544e8a968d1fc17fd024ac53d39871e214cdd168d75bf82fd"
},
"downloads": -1,
"filename": "rdfreader-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b5b009ce63e8faff6c44593ff23dbbe0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 16790,
"upload_time": "2025-09-06T14:18:12",
"upload_time_iso_8601": "2025-09-06T14:18:12.533103Z",
"url": "https://files.pythonhosted.org/packages/c4/55/b52cea0602e8c67a07ba95a675c1b6c5550975dc91a1e5efc605f17bc76b/rdfreader-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "20f885a448b17a4c48c6b0c5e7fdf1f433652960d21f50b0839808ffb855de5e",
"md5": "28f4e41c5fae3a1dc6844ad66149449a",
"sha256": "8097f184339ac4676530b39289461e372b0a85ebd8b889f0fc5e7fd3e42aa193"
},
"downloads": -1,
"filename": "rdfreader-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "28f4e41c5fae3a1dc6844ad66149449a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 14091,
"upload_time": "2025-09-06T14:18:13",
"upload_time_iso_8601": "2025-09-06T14:18:13.714015Z",
"url": "https://files.pythonhosted.org/packages/20/f8/85a448b17a4c48c6b0c5e7fdf1f433652960d21f50b0839808ffb855de5e/rdfreader-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-06 14:18:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ChemAILtd",
"github_project": "rdfreader",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "rdfreader"
}