Skip to content

Commit

Permalink
fix: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohulan committed Feb 22, 2024
1 parent 11ea923 commit 3820cb2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 46 deletions.
69 changes: 25 additions & 44 deletions app/modules/toolkits/cdk_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,37 @@
from jpype import JVMNotFoundException
from jpype import startJVM


# Start JVM to use CDK in python
try:
jvmPath = getDefaultJVMPath()
except JVMNotFoundException:
print(
"If you see this message, for some reason JPype",
"cannot find jvm.dll.",
"This indicates that the environment variable JAVA_HOME",
"is not set properly.",
"You can set it or set it manually in the code",
)
print("If you see this message, for some reason JPype cannot find jvm.dll.")
print("This indicates that the environment variable JAVA_HOME is not set properly.")
print("You can set it or set it manually in the code")

Check warning on line 22 in app/modules/toolkits/cdk_wrapper.py

View check run for this annotation

Codecov / codecov/patch

app/modules/toolkits/cdk_wrapper.py#L20-L22

Added lines #L20 - L22 were not covered by tests
jvmPath = "Define/path/or/set/JAVA_HOME/variable/properly"
if not isJVMStarted():
cdk_path = "https://github.com/cdk/cdk/releases/download/cdk-2.9/cdk-2.9.jar"
sru_path = "https://github.com/JonasSchaub/SugarRemoval/releases/download/v1.3.2/SugarRemovalUtility-jar-with-dependencies.jar"
centres_path = (
"https://github.com/SiMolecule/centres/releases/download/1.0/centres.jar"
)
opsin_path = "https://github.com/dan2097/opsin/releases/download/2.8.0/opsin-cli-2.8.0-jar-with-dependencies.jar"

cdkjar_path = str(pystow.join("STOUT-V2")) + "/cdk-2.9.jar"
srujar_path = (
str(pystow.join("STOUT-V2")) + "/SugarRemovalUtility-jar-with-dependencies.jar"
)
centresjar_path = str(pystow.join("STOUT-V2")) + "/centres.jar"
opsinjar_path = (
str(pystow.join("STOUT-V2")) + "/opsin-cli-2.8.0-jar-with-dependencies.jar"
)

if not os.path.exists(cdkjar_path):
jar_path = pystow.ensure("STOUT-V2", url=cdk_path)

if not os.path.exists(srujar_path):
jar_path = pystow.ensure("STOUT-V2", url=sru_path)

if not os.path.exists(centresjar_path):
jar_path = pystow.ensure("STOUT-V2", url=centres_path)

if not os.path.exists(opsinjar_path):
jar_path = pystow.ensure("STOUT-V2", url=opsin_path)

startJVM(
"-ea",
"-Xmx4096M",
classpath=[cdkjar_path, srujar_path, centresjar_path, opsinjar_path],
)
cdk_base = "org.openscience.cdk"
opsin_base = JPackage("uk").ac.cam.ch.wwmm.opsin
_nametostruct = opsin_base.NameToStructure.getInstance()
_restoinchi = opsin_base.NameToInchi.convertResultToInChI
if not isJVMStarted():
paths = {
"cdk-2.9": "https://github.com/cdk/cdk/releases/download/cdk-2.9/cdk-2.9.jar",
"SugarRemovalUtility-jar-with-dependencies": "https://github.com/JonasSchaub/SugarRemoval/releases/download/v1.3.2/SugarRemovalUtility-jar-with-dependencies.jar",
"centres": "https://github.com/SiMolecule/centres/releases/download/1.0/centres.jar",
"opsin-cli-2.8.0-jar-with-dependencies": "https://github.com/dan2097/opsin/releases/download/2.8.0/opsin-cli-2.8.0-jar-with-dependencies.jar",
}

jar_paths = {
key: str(pystow.join("STOUT-V2")) + f"/{key}.jar" for key in paths.keys()
}
for key, url in paths.items():
if not os.path.exists(jar_paths[key]):
pystow.ensure("STOUT-V2", url=url)

startJVM("-ea", "-Xmx4096M", classpath=[jar_paths[key] for key in jar_paths])

cdk_base = "org.openscience.cdk"
opsin_base = JPackage("uk").ac.cam.ch.wwmm.opsin
_nametostruct = opsin_base.NameToStructure.getInstance()
_restoinchi = opsin_base.NameToInchi.convertResultToInChI


def get_CDK_IAtomContainer(smiles: str):
Expand Down
4 changes: 2 additions & 2 deletions app/routers/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ async def hose_codes(
default="rdkit",
description="Cheminformatics toolkit used in the backend",
),
ringsize: Optional[bool] = Query(
ringsize: bool = Query(
False,
title="ringsize",
description="Determines whether to include information about ring sizes",
Expand Down Expand Up @@ -498,7 +498,7 @@ async def check_errors(
},
},
),
fix: Optional[bool] = Query(
fix: bool = Query(
False,
title="Fix",
description="Flag indicating whether to fix the issues by standardizing the SMILES.",
Expand Down

0 comments on commit 3820cb2

Please sign in to comment.