Skip to content

Commit

Permalink
xchem#48 add computation of #cpd property
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 10, 2020
1 parent 3ee0c2c commit 3fa076b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/components/preview/molecule/helperConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const moleculeProperty = {
rings: 'Rings',
velec: 'Velec',
cpd: '#cpd',
vectors: '#vctrs'
vectors: '#vctr'
};
8 changes: 5 additions & 3 deletions js/components/preview/molecule/moleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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(() => {
Expand Down
8 changes: 8 additions & 0 deletions js/components/preview/molecule/molecules_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 3fa076b

Please sign in to comment.