Skip to content

Commit 04c563a

Browse files
committed
cleanup for new release
1 parent 15f71c2 commit 04c563a

File tree

6 files changed

+22
-47
lines changed

6 files changed

+22
-47
lines changed

Pipfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ name = "pypi"
55

66
[packages]
77
cairosvg = "==2.7.0"
8-
bs4 = "*"
98
urllib3 = "*"
109

1110
[dev-packages]

Pipfile.lock

Lines changed: 1 addition & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

comchem/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
import cairosvg
44
import os
5-
from bs4 import BeautifulSoup
65
from urllib.request import urlopen
76

87
ccpath = 'https://commonchemistry.cas.org/api/'
@@ -18,7 +17,7 @@ def detail(casrn, field="all"):
1817
:param field: field to return or all fields (default)
1918
:return mixed
2019
"""
21-
if not _validcas(casrn):
20+
if not __validcas(casrn):
2221
return '' # false
2322
url = ccpath + 'detail?cas_rn=' + casrn
2423
respnse = urlopen(url)
@@ -46,7 +45,7 @@ def query(term='', exact=False):
4645
:return: string
4746
"""
4847
url = ''
49-
if _validkey(term):
48+
if __validkey(term):
5049
url = ccpath + 'search?q=InChIKey=' + term # InChIKey search
5150
elif exact is False and term[-1:] != '*':
5251
url = ccpath + 'search?q=' + term + '*'
@@ -57,8 +56,7 @@ def query(term='', exact=False):
5756
out = [] # false
5857
if jsn['results']:
5958
for hit in jsn['results']:
60-
textname = BeautifulSoup(hit["name"], "lxml").text
61-
out.append({"textname": textname, "htmlname": hit["name"].lower(), "rn": hit["rn"]})
59+
out.append({"name": hit["name"].lower(), "rn": hit["rn"]})
6260
return out
6361

6462

@@ -67,7 +65,7 @@ def key2cas(key):
6765
Find the CAS Registry Number of a chemical substance using an IUPAC InChIKey
6866
:param key - a valid InChIKey
6967
"""
70-
if _validkey(key):
68+
if __validkey(key):
7169
hits = query('InChIKey=' + key, True)
7270
if hits:
7371
if len(hits) == 1:
@@ -92,16 +90,17 @@ def key2cas(key):
9290
def chemimg(chemid='', imgtype='svg'):
9391
"""
9492
Get an image for a compound from either a CAS Registry Number, InChIKey, SMILES, or name
93+
Uses carioSVG (https://www.courtbouillon.org/cairosvg)
9594
:param chemid: the CAS Registry Number, InChIKey, SMILES, or name
9695
:param imgtype: the type of image file to produce - svg, png, or ps
9796
:return:
9897
"""
9998
# check identifier for type so checking can be done
10099
if chemid == '':
101100
return False
102-
if _validkey(chemid):
101+
if __validkey(chemid):
103102
casrn = key2cas(chemid)
104-
elif not _validcas(chemid):
103+
elif not __validcas(chemid):
105104
casrn = query(chemid, True)
106105
else:
107106
casrn = chemid
@@ -122,7 +121,7 @@ def chemimg(chemid='', imgtype='svg'):
122121
return True
123122

124123

125-
def _validkey(key):
124+
def __validkey(key):
126125
"""
127126
Validate and IUPAC InChIKey
128127
:param key: a string to be validated as an IUPAC InChIKey
@@ -134,7 +133,7 @@ def _validkey(key):
134133
return True
135134

136135

137-
def _validcas(cas):
136+
def __validcas(cas):
138137
"""
139138
Validate a CAS Registry Number
140139
See: https://en.wikipedia.org/wiki/CAS_Registry_Number#Format

example.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
from comchem import *
22
import json
33

4-
rundef = "cas2png"
54

6-
if rundef == "props":
5+
def props(casrn='57-83-0'):
76
# gets the properties for the CASRN requested
8-
cmpd = detail("9003-07-0", "properties")
7+
cmpd = detail(casrn, "properties")
98
print(json.dumps(cmpd, indent=4))
10-
exit()
119

12-
if rundef == "trifl":
10+
def trifl():
1311
# gets a list of all compounds starting with "trifluoro*"
1412
hits = query("trifluoro*")
1513
print(hits)
1614

17-
if rundef == "key2cas":
15+
def key2cas():
1816
# convert a substance CASRN into its InChIKey
17+
# uses code to find the lowest molecular weight hit for the InChIkey
1918
casrn = key2cas('UHOVQNZJYSORNB-UHFFFAOYSA-N')
2019
print(casrn)
2120

22-
if rundef == "cas2png":
21+
def cas2png(casrn='57-83-0'):
2322
# create a png of a molecule based on its CASRN (via SVG from ComChem)
24-
chemimg("57-83-0", 'png')
23+
chemimg(casrn, 'png')
24+
print('image saved to ' + casrn + '.py')
25+
26+
trifl()

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "PyComChem"
3-
version = "0.2"
3+
version = "0.3"
44
description = "Python library for accessing the CommonChemistry.org API"
55
authors = ["Stuart Chalk <schalk@unf.edu>"]
66
license = "MIT"
@@ -18,7 +18,6 @@ packages = [
1818
]
1919
[tool.poetry.dependencies]
2020
python = "^3.7"
21-
bs4 = "0.0.1"
2221
cairosvg = "^2.5.2"
2322

2423
[tool.poetry.dev-dependencies]

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pyComChem
3-
version = 0.2
3+
version = 0.3
44
url = https://github.com/stuchalk/pyComChem
55
author = 'Stuart Chalk'
66
author_email = 'schalk@unf.edu'
@@ -17,4 +17,3 @@ python_requires = >=3.7
1717

1818
[flake8]
1919
# add options
20-

0 commit comments

Comments
 (0)