From 3fa076bd170f445c9d3b360be1fca518e8c33e4a Mon Sep 17 00:00:00 2001 From: Tibor Postek Date: Mon, 17 Feb 2020 10:53:12 +0100 Subject: [PATCH] #48 add computation of #cpd property --- js/components/preview/molecule/helperConstants.js | 2 +- js/components/preview/molecule/moleculeView.js | 8 +++++--- js/components/preview/molecule/molecules_helpers.js | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/js/components/preview/molecule/helperConstants.js b/js/components/preview/molecule/helperConstants.js index 0db80778d..c3610168d 100644 --- a/js/components/preview/molecule/helperConstants.js +++ b/js/components/preview/molecule/helperConstants.js @@ -9,5 +9,5 @@ export const moleculeProperty = { rings: 'Rings', velec: 'Velec', cpd: '#cpd', - vectors: '#vctrs' + vectors: '#vctr' }; diff --git a/js/components/preview/molecule/moleculeView.js b/js/components/preview/molecule/moleculeView.js index 8eb3e1cf3..473a55481 100644 --- a/js/components/preview/molecule/moleculeView.js +++ b/js/components/preview/molecule/moleculeView.js @@ -18,6 +18,7 @@ import { moleculeProperty } from './helperConstants'; import { ComputeSize } from '../../../utils/computeSize'; import { api } from '../../../utils/api'; import { generateObjectList } from '../../session/helpers'; +import { getTotalCountOfCompounds } from './molecules_helpers'; const useStyles = makeStyles(theme => ({ container: { @@ -130,6 +131,7 @@ const MoleculeView = memo( }) => { const [state, setState] = useState(); const [countOfVectors, setCountOfVectors] = useState('-'); + const [cmpds, setCmpds] = useState('-'); const selectedAll = useRef(false); const viewRef = useRef(); const currentID = (data && data.id) || undefined; @@ -168,7 +170,7 @@ const MoleculeView = memo( { name: moleculeProperty.rots, value: data.rots }, { name: moleculeProperty.rings, value: data.rings }, { name: moleculeProperty.velec, value: data.velec }, - { name: moleculeProperty.cpd, value: '???' } + { name: moleculeProperty.cpd, value: cmpds } ]; // componentDidMount @@ -188,8 +190,8 @@ const MoleculeView = memo( }), api({ url: `${base_url}/api/vector/${data.id}` }).then(response => { const vectors = response.data.vectors['3d']; - const cmpds = generateObjectList(vectors, {}); - setCountOfVectors(cmpds.length); + setCmpds(getTotalCountOfCompounds(vectors)); + setCountOfVectors(generateObjectList(vectors).length); }) ]).catch(error => { setState(() => { diff --git a/js/components/preview/molecule/molecules_helpers.js b/js/components/preview/molecule/molecules_helpers.js index 0314d0ecd..391de3c66 100644 --- a/js/components/preview/molecule/molecules_helpers.js +++ b/js/components/preview/molecule/molecules_helpers.js @@ -43,3 +43,11 @@ export const generateSphere = (data, selected = false) => { coords: [data.x_com, data.y_com, data.z_com] }; }; + +export const getTotalCountOfCompounds = vectors => { + let tot_num = 0; + Object.keys(vectors).forEach(key => { + tot_num += vectors[key].addition ? vectors[key].addition.length : 0; + }); + return tot_num; +};