Skip to content

Commit

Permalink
improved regex string in _validate function; updated examples to run …
Browse files Browse the repository at this point in the history
…using variable; converted interpreter to use pipenv
  • Loading branch information
stuchalk committed Nov 4, 2022
1 parent d2b7d82 commit 72fda4e
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 9 deletions.
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
cairosvg = "*"
bs4 = "*"
urllib3 = "*"

[dev-packages]

[requires]
python_version = "3.10"
239 changes: 239 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion comchem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _validkey(key):
:param key: a string to be validated as an IUPAC InChIKey
:return: bool
"""
test = re.search(r'^[A-Z]{14}-[A-Z]{8}[SN][A]-[A-Z]$', key)
test = re.search(r'^[A-Z]{14}-[A-Z]{8}[SN]A-[A-Z]$', key)
if test is None:
return False
return True
Expand Down
26 changes: 18 additions & 8 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
from comchem import *
import json

cmpd = detail("9003-07-0", "properties")
print(json.dumps(cmpd, indent=4))
exit()
rundef = "cas2png"

hits = query("trifluoro*")
print(hits)
if rundef == "props":
# gets the properties for the CASRN requested
cmpd = detail("9003-07-0", "properties")
print(json.dumps(cmpd, indent=4))
exit()

casrn = key2cas('UHOVQNZJYSORNB-UHFFFAOYSA-N')
print(casrn)
if rundef == "trifl":
# gets a list of all compounds starting with "trifluoro*"
hits = query("trifluoro*")
print(hits)

chemimg("71-43-2", 'png')
if rundef == "key2cas":
# convert a substance CASRN into its InChIKey
casrn = key2cas('UHOVQNZJYSORNB-UHFFFAOYSA-N')
print(casrn)

if rundef == "cas2png":
# create a png of a molecule based on its CASRN (via SVG from ComChem)
chemimg("57-83-0", 'png')

0 comments on commit 72fda4e

Please sign in to comment.