manufac-analytics / inchi

InChI for NodeJS/TypeScript
https://manufac-analytics.github.io/inchi/
MIT License
0 stars 1 forks source link

Instantiate different type strucs #9

Closed maneetgoyal closed 3 years ago

maneetgoyal commented 3 years ago

For example, we already have the following now in src/headers.ts:

//  typedef struct tagInchiAtom {
//     /* atom coordinates */
//     double x;
//     double y;
//     double z;
//     /* connectivity */
//     AT_NUM  neighbor[MAXVAL];     /* adjacency list: ordering numbers of */
//                                   /*            the adjacent atoms, >= 0 */
//     S_CHAR  bond_type[MAXVAL];    /* inchi_BondType */
//     /* 2D stereo */
//     S_CHAR  bond_stereo[MAXVAL];  /* inchi_BondStereo2D; negative if the */
//                                   /* sharp end points to opposite atom */
//     /* other atom properties */
//     char    elname[ATOM_EL_LEN];  /* zero-terminated chemical element name:*/
//                                   /* "H", "Si", etc. */
//     AT_NUM  num_bonds;            /* number of neighbors, bond types and bond*/
//                                   /* stereo in the adjacency list */
//     S_CHAR  num_iso_H[NUM_H_ISOTOPES + 1]; /* implicit hydrogen atoms */
//                                   /* [0]: number of implicit non-isotopic H
//                                        (exception: num_iso_H[0]=-1 means INCHI
//                                        adds implicit H automatically),
//                                      [1]: number of implicit isotopic 1H (protium),
//                                      [2]: number of implicit 2H (deuterium),
//                                      [3]: number of implicit 3H (tritium) */
//     AT_NUM  isotopic_mass;        /* 0 => non-isotopic; isotopic mass or  */
//                                   /* ISOTOPIC_SHIFT_FLAG + mass - (average atomic mass) */
//     S_CHAR  radical;              /* inchi_Radical */
//     S_CHAR  charge;               /* positive or negative; 0 => no charge */
// }inchi_Atom;

export const inchi_Atom = NAPIStructType({
  x: refNAPI.types.double,
  y: refNAPI.types.double,
  z: refNAPI.types.double,
  neighbor: NAPIArrayType(refNAPI.types.short, MAXVAL),
  bond_type: NAPIArrayType(refNAPI.types.char, MAXVAL),
  bond_stereo: NAPIArrayType(refNAPI.types.char, MAXVAL),
  elname: NAPIArrayType(refNAPI.types.char, ATOM_EL_LEN),
  num_bonds: refNAPI.types.short,
  num_iso_H: NAPIArrayType(refNAPI.types.char, NUM_H_ISOTOPES + 1),
  isotopic_mass: refNAPI.types.short,
  radical: refNAPI.types.char,
  charge: refNAPI.types.char,
});

Now we want the following in tests/examples.test.ts:

/**
 * Instantiate inchi_Atom
 */
const inchiAtom = new inchi_Atom({
  // @ts-ignore
  x: 1.1,
  y: 2.2,
  z: 3.3,
  neighbor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  bond_type: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  bond_stereo: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  elname: [1, 2, 3, 4, 5, 6],
  num_bonds: 3,
  num_iso_H: [1, 2, 3, 4],
  isotopic_mass: 10,
  radical: 2,
  charge: -2,
});
strict.equal(inchiAtom.x, 1.1);
strict.equal(inchiAtom.y, 2.2);
strict.equal(inchiAtom.z, 3.3);
strict.equal(inchiAtom.neighbor.toArray().length, MAXVAL);
strict.equal(inchiAtom.bond_type.toArray().length, MAXVAL);
strict.equal(inchiAtom.bond_stereo.toArray().length, MAXVAL);
strict.equal(inchiAtom.elname.toArray().length, ATOM_EL_LEN);
strict.equal(inchiAtom.num_bonds, 3);
strict.equal(inchiAtom.num_iso_H.toArray().length, NUM_H_ISOTOPES + 1);
strict.equal(inchiAtom.isotopic_mass, 10);
strict.equal(inchiAtom.radical, 2);
strict.equal(inchiAtom.charge, -2);
maneetgoyal commented 3 years ago

@saiprasadsamudrala Start on this when you are ready.

maneetgoyal commented 3 years ago

For reference for our users/contributors: https://github.com/node-ffi-napi/ref-struct-di/issues/17

maneetgoyal commented 3 years ago

Have instantiated some types in https://github.com/manufac-analytics/inchi/blob/main/tests/examples.test.ts. It should give you hints on how to move forward.