https://github.com/harshil21/carbonpy
An Organic Chemistry module
https://github.com/harshil21/carbonpy
bonds carbon chemistry compound iupac organic-chemistry pip python3
Last synced: about 2 months ago
JSON representation
An Organic Chemistry module
- Host: GitHub
- URL: https://github.com/harshil21/carbonpy
- Owner: harshil21
- License: apache-2.0
- Created: 2019-10-25T17:47:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-26T14:39:44.000Z (about 2 years ago)
- Last Synced: 2025-03-14T19:17:04.882Z (2 months ago)
- Topics: bonds, carbon, chemistry, compound, iupac, organic-chemistry, pip, python3
- Language: Python
- Homepage:
- Size: 67.4 KB
- Stars: 15
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Carbonpy
A module which names straight/branched chain organic compounds, suggests conversions from one type to another, etc.[](https://pepy.tech/project/carbonpy) [](https://pepy.tech/project/carbonpy/month) [](https://pepy.tech/project/carbonpy/week) 
## Installation- You can install or upgrade carbonpy with:
```
$ pip install carbonpy --upgrade
```
- Building from source:
```
$ git clone https://github.com/harshil21/carbonpy --recursive
$ cd carbonpy
$ python setup.py install
```
## Usage### Syntax for representing bonds:
Single bond: -
Double bond: =
Triple bond: ~Examples: `CH3-CH3`, `CH2=CH2`, `CH~CH`
### Naming compounds:
Instantiate the class `Namer()` , which takes a string which contains the hydrocarbon (condensed form) and then call it with a method named `analyser()` to get the IUPAC name of the compound.
Example:
``` python
from carbonpy import Namercompound = Namer('CH~CH')
print(compound.analyser())>>> 'Eth-1-yne'
```You can also get the molecular formula of a compound:
```python
compound = Namer('CH~C-C~C-CH=C=C=CH2')
print(compound.molecular_formula())
>>> 'C₈H₄'
```Or get the number of carbons/hydrogens in the compound by using the attributes:
```python
compound = Namer('CH4')
carbs = compound.carbons
hydros = compound.hydrogensprint(f"Carbons: {carbs}, Hydrogens: {hydros}")
>>> 'Carbons: 1, Hydrogens: 4'
```Once branches are supported, 2-Methylpropane would be expressed as:
```
a = Namer('CH3-CH(CH3)-CH3').analyser()
>>> 2-Methylpropane
```Will support naming with functional groups in the future.