Skip to content

Commit

Permalink
Add SMILES limitation for 300 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
luk27official committed Apr 29, 2024
1 parent eb7cc5d commit 5e75026
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
9 changes: 4 additions & 5 deletions frontend/client/tasks/server-docking-task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ export async function computeDockingTaskOnBackend(prediction: PredictionInfo, po
"bounding_box": box
}),
}).then((res) => {
console.log(res);
}
).catch(err => {
console.log(err);
return res.json();
}).catch(err => {
console.error(err);
return null;
});
return;
}

/**
Expand Down
13 changes: 11 additions & 2 deletions frontend/client/viewer/components/tasks-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export default function TasksTab(props: { pockets: PocketData[], predictionInfo:

setInvalidInput(false);
const smiles = params[0].replaceAll(" ", "");
// check if SMILES is < 300 characters, otherwise
// TODO: add an option to prepare a script that will run DODO with the ligand
if (smiles.length > 300) {
setInvalidInput(true);
return;
}

let savedTasks = localStorage.getItem(`${props.predictionInfo.id}_serverTasks`);
if (!savedTasks) savedTasks = "[]";
Expand All @@ -103,10 +109,13 @@ export default function TasksTab(props: { pockets: PocketData[], predictionInfo:
"discriminator": "server",
});
localStorage.setItem(`${props.predictionInfo.id}_serverTasks`, JSON.stringify(tasks));
computeDockingTaskOnBackend(props.predictionInfo, props.pockets[pocketIndex], smiles, props.plugin, exhaustiveness);
const taskPostRequest = computeDockingTaskOnBackend(props.predictionInfo, props.pockets[pocketIndex], smiles, props.plugin, exhaustiveness);
if (taskPostRequest === null) {
tasks[tasks.length - 1].status = "failed";
}
},
parameterDescriptions: [
"Enter the molecule in SMILES format (e.g. c1ccccc1)",
"Enter the molecule in SMILES format (e.g. c1ccccc1), max 300 characters",
"Enter the exhaustiveness for Autodock Vina (recommended: 32, allowed range: 1-64)"
],
parameterDefaults: ["", "32"]
Expand Down
17 changes: 17 additions & 0 deletions web-server/src/docking_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ def post_task(self, prediction_id: str, data: dict):
if data is None: #user did not provide any data with the post request
return "", 400

required_fields = ["hash", "pocket", "smiles", "exhaustiveness", "bounding_box"]
for field in required_fields:
if field not in data:
return f"Field {field} is missing.", 400

# those boundaries are arbitrary - given in the tsx task file
if len(data["smiles"]) > 300:
return "The requested SMILES is too long.", 400

try:
exhaustiveness = int(data["exhaustiveness"])
# the exhaustiveness parameter must be a number between 1 and 64
if exhaustiveness < 1 or exhaustiveness > 64:
raise ValueError
except ValueError:
return "The exhaustiveness parameter must be a number between 1 and 64.", 400

taskinfo = TaskInfo(directory=directory, identifier=prediction_id, data=data)

if os.path.exists(directory) and os.path.exists(_info_file(taskinfo)):
Expand Down

0 comments on commit 5e75026

Please sign in to comment.