private static void CreateStereos(NInchiStructure output, int numstereo, IntPtr intPtrStereos) { var istereos = (Inchi_Stereo0D *)intPtrStereos.ToPointer(); for (int i = 0; i < numstereo; i++) { // jobject atC, an0, an1, an2, an3, stereo; Inchi_Stereo0D istereo = istereos[i]; NInchiAtom atC = null; if (istereo.central_atom != NO_ATOM) { atC = output.Atoms[istereo.central_atom]; } var an0 = output.Atoms[istereo.neighbor[0]]; var an1 = output.Atoms[istereo.neighbor[1]]; var an2 = output.Atoms[istereo.neighbor[2]]; var an3 = output.Atoms[istereo.neighbor[3]]; var stereo = new NInchiStereo0D(atC, an0, an1, an2, an3, (INCHI_STEREOTYPE)istereo.type, (INCHI_PARITY)istereo.parity); output.Stereos.Add(stereo); } }
static Set_inchi_Input_ InitInchiInput(NInchiInput input) { var natoms = input.Atoms.Count; var nstereo = input.Stereos.Count; var nbonds = input.Bonds.Count; if (natoms > MAX_ATOMS) { throw new ArgumentException("Too many atoms"); } var atoms = new Inchi_Atom[natoms]; { for (int i = 0; i < natoms; i++) { var atom = input.Atoms[i]; Inchi_Atom iatom = new Inchi_Atom(); { var elname = Encoding.ASCII.GetBytes(atom.ElementType); for (int n = 0; n < elname.Length; n++) { iatom.elname[n] = (sbyte)elname[n]; } iatom.elname[elname.Length] = 0; } iatom.X = atom.X; iatom.Y = atom.Y; iatom.Z = atom.Z; iatom.charge = (SByte)atom.Charge; iatom.radical = (SByte)atom.Radical; iatom.num_iso_H[0] = (SByte)atom.ImplicitH; iatom.num_iso_H[1] = (SByte)atom.ImplicitProtium; iatom.num_iso_H[2] = (SByte)atom.ImplicitDeuterium; iatom.num_iso_H[3] = (SByte)atom.ImplicitTritium; iatom.isotopic_mass = (Int16)atom.IsotopicMass; iatom.num_bonds = 0; atoms[i] = iatom; } } { for (int i = 0; i < nbonds; i++) { var bond = input.Bonds[i]; var atomO = bond.OriginAtom; var atomT = bond.TargetAtom; var bondType = bond.BondType; var bondStereo = bond.BondStereo; var iaO = input.Atoms.IndexOf(atomO); var iaT = input.Atoms.IndexOf(atomT); var iatom = atoms[iaO]; int numbonds = atoms[iaO].num_bonds; if (numbonds == MAXVAL) { throw new ArgumentException("Too many bonds from one atom; maximum: " + MAXVAL); } iatom.neighbor[numbonds] = (Int16)iaT; iatom.bond_type[numbonds] = (SByte)bondType; iatom.bond_stereo[numbonds] = (SByte)bondStereo; iatom.num_bonds++; atoms[iaO] = iatom; } } var stereos = new Inchi_Stereo0D[nstereo]; { for (var i = 0; i < input.Stereos.Count; i++) { var stereo = input.Stereos[i]; var istereo = stereos[i]; var cat = stereo.CentralAtom; var nat0 = stereo.Neighbors[0]; var nat1 = stereo.Neighbors[1]; var nat2 = stereo.Neighbors[2]; var nat3 = stereo.Neighbors[3]; istereo.central_atom = (Int16)input.Atoms.IndexOf(cat); istereo.neighbor[0] = (Int16)input.Atoms.IndexOf(nat0); istereo.neighbor[1] = (Int16)input.Atoms.IndexOf(nat1); istereo.neighbor[2] = (Int16)input.Atoms.IndexOf(nat2); istereo.neighbor[3] = (Int16)input.Atoms.IndexOf(nat3); istereo.type = (SByte)stereo.StereoType; istereo.parity = (SByte)stereo.Parity; stereos[i] = istereo; } } var pre = new Set_inchi_Input_ { atoms = atoms, stereos = stereos }; return(pre); }