Chemical Property Prediction
Introduction
This guide will go over how to make use of chemical property prediction workflow using the API. You will need to make sure you are importing the OS
library into your python code.
Finding The Module
The first thing you need to find is the id
for the chemical prediction module, which can be found at the /layar/module
.
moduleUrl = f'{envUrl}/layar/module'
moduleId = ""
header = {'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Vyasa-Data-Providers': 'internal-prod.certara.ai',
'Authorization': f"Bearer {token}",
'X-Vyasa-Data-Fabric': fabricId}
response = requests.get(moduleUrl, headers = header).json()
for i in response:
if i.get("name") == 'Molecular Property Prediction':
moduleId = i.get("id")
else:
continue
Create The Project
With the moduleId
we can create the project using the /layar/project
endpoint.
projectUrl = f'{envUrl}/layar/project'
body = {
'moduleId': moduleId,
'name': 'test predict',
'description': 'test predict'}
response = requests.post(projectUrl, headers = header, json = body).json()
projectId = response.get("id")
Start The Project
Start the project using the projectId
and the /layar/project/projectId/run
endpoint. We can then use the /layar/projectComputation/projectId
endpoint to check the status.
projectRunUrl = f'{envUrl}/layar/project/{projectId}/run'
body = {
'computationParameters': {
'smiles_raw': '<SMILE strings seperated by new lines>'},
'moduleId': moduleId
}
response = requests.post(projectRunUrl, headers = header, json = body).json()
status = None
while status != 'complete':
response = requests.get(f'{envUrl}/layar/projectComputation/{projectId}',
headers = header
).json().get("status")
if response == 'Complete!':
status = 'complete'
print(id + ' Done running')
return id
else:
status = None
Download Results
You can then download the results of the prediction using the /layar/projectComputation/projectId/download
endpoint.
downloadProjectUrl = f'{envUrl}/layar/projectComputation/{projectId}/download?access_token={token}'
placeFile = 'C:\users\test\downloads\'
#functions to extract filename from request headers and make sure they are in an acceptable format
def getFileName(cd):
fname = re.findall('filename=(.+)', cd)
fname = fname[0]
fname = fname.replace('"', '')
fname = fname.replace(';', '')
return fname
def sanitizeName(name):
length = len(name)
while length > 150:
name = name[:140]
length = len(name)
return name
response = requests.get(downloadProjectUrl,
headers = {'Accept': 'application/json'},
stream = True)
name = getFileName(response.headers.get('content-disposition'))
name = sanitizeName(name)
with open(f'{placeFile}/{name}.csv', 'wb') as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
Updated about 6 hours ago