Skip to content

Commit bac838a

Browse files
authored
round lattice parameters from materials project (#61)
1 parent 3733907 commit bac838a

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

web-conexs-client/src/components/crystals/MatProjCrystalViewer.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
22
import { getMatProjStructure, postCrystal } from "../../queryfunctions";
3-
import { Button, Stack, Typography } from "@mui/material";
4-
import React from "react";
3+
import { Button, Checkbox, Stack, Typography } from "@mui/material";
4+
import React, { useState } from "react";
55
import { useNavigate } from "react-router-dom";
66
import XYZCrystalViewer from "./XYZCrystalViewer";
77
import { MolStarCrystalWrapper } from "../MolstarCrystalViewer";
@@ -15,6 +15,12 @@ function MatProjCrystalViewer(props: { mpid: string }) {
1515
retry: false,
1616
});
1717

18+
const [checked, setChecked] = useState(false);
19+
20+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
21+
setChecked(event.target.checked);
22+
};
23+
1824
const navigate = useNavigate();
1925
const queryClient = useQueryClient();
2026

@@ -55,10 +61,31 @@ function MatProjCrystalViewer(props: { mpid: string }) {
5561
labelledAtomIndex={undefined}
5662
></MolStarCrystalWrapper>
5763
</Stack>
64+
<Stack direction="row" alignItems="center">
65+
<Checkbox checked={checked} onChange={handleChange}></Checkbox>
66+
<Typography>Round Lattice Parameters to 4 Decimal Places</Typography>
67+
</Stack>
5868
<Button
5969
variant="contained"
6070
onClick={() => {
61-
mutation.mutate(query.data);
71+
const structure = query.data;
72+
73+
if (checked) {
74+
structure.lattice.a =
75+
Math.round(structure.lattice.a * 10000.0) / 10000.0;
76+
structure.lattice.b =
77+
Math.round(structure.lattice.b * 10000.0) / 10000.0;
78+
structure.lattice.c =
79+
Math.round(structure.lattice.c * 10000.0) / 10000.0;
80+
structure.lattice.alpha =
81+
Math.round(structure.lattice.alpha * 10000.0) / 10000.0;
82+
structure.lattice.beta =
83+
Math.round(structure.lattice.beta * 10000.0) / 10000.0;
84+
structure.lattice.gamma =
85+
Math.round(structure.lattice.gamma * 10000.0) / 10000.0;
86+
}
87+
88+
mutation.mutate(structure);
6289
}}
6390
>
6491
Create Crystal

0 commit comments

Comments
 (0)