Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Molecule investigation #59

Open
wants to merge 3 commits into
base: update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backend/app/app/api/v2/endpoints/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,13 @@ def search_neighbors(
raise HTTPException(
status_code=400, detail="No molecule with the id provided was found!"
)

return results
# If a molecule does not have UMAP or PCA data, the results returned will just be molecules from id 1 to the limit.
# The easiest way to check if the molecule has PCA or UMAP data is to see if the first molecule returned is the same as the one requested since the distance should be 0.
if (results[0][1] == molecule_id):
return results
else:
# Return a 204 since the query executed but there is no real UMAP or PCA data.
return Response(status_code=204)


@router.get("/dimensions/", response_model=List[schemas.MoleculeComponents])
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/pages/Molecule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ async function dimensionality(molecule_id, type, components, signal, limit=10) {
if (!response.ok) {
throw new Error('Invalid Molecule Id')
}

else if (response.status == 204) {
// Return an empty array because there is no PCA or UMAP data.
return [];
}
else {
return await response.json()
}
Expand Down Expand Up @@ -169,7 +172,9 @@ export default function MoleculeInfo() {

return (
<Container maxWidth="xl">
<Grid container alignItems="center" justifyContent="center" spacing={2}>

{ Object.keys(molData).length > 0 ?
<Grid container alignItems="center" justifyContent="center" spacing={2}>
<Grid item xs={(width > 1366) ? 6 : 12} sx={{mt: 3}}>
{Object.keys(svg).length > 0 &&
<Box
Expand All @@ -195,7 +200,7 @@ export default function MoleculeInfo() {
<Grid item xs={(width > 1366) ? 6 : 12}>
{Object.keys(molData).length > 0 && <MoleculeDataTable molecule_id={molData.molecule_id} initial_data_type="ml" />}
</Grid>
{(width > 768) && allConformers.length > 0 && conformer.length > 0 && <Grid item xs={(width > 1366) ? 6 : 12}>
{(width > 768) && allConformers.length > 0 && conformer.length > 0 && <Grid item xs={(width > 1366) && Object.keys(neighborData).length > 0 ? 6 : 12}>
<Container>
<FormControl fullWidth variant="standard">
<InputLabel id="conformer">Conformer</InputLabel>
Expand All @@ -219,8 +224,8 @@ export default function MoleculeInfo() {
</Box>
</Container>
</Grid>}
{(width > 768) && <Grid item xs={(width > 1366) && allConformers.length > 0 && conformer.length > 0 ? 6 : 12}>
{Object.keys(neighborData).length > 0 ?
{(width > 768) && Object.keys(neighborData).length > 0 && <Grid item xs={(width > 1366) && allConformers.length > 0 && conformer.length > 0 ? 6 : 12}>
{Object.keys(neighborData).length > 0 &&
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="center">
<TextField
select
Expand All @@ -236,16 +241,13 @@ export default function MoleculeInfo() {
<Graph molData={neighborData} componentArray={components} type={type} neighborSearch={true}></Graph>
</Container>
</Box>
:
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="center">
<CircularProgress />
</Box>
}
</Grid>
}
{Object.keys(molData).length > 0 && (width > 768) && <Grid item xs={12}>
</Grid>}
</Grid>
</Grid> :
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="center">
<CircularProgress />
</Box>}
</Container>
)
}