/// <summary> /// Mass number for a atom with a given atomic number and exact mass. /// </summary> /// <param name="atomicNumber">atomic number</param> /// <param name="exactMass">exact mass</param> /// <returns>the mass number (or <see langword="null"/>>) if no mass number was found</returns> /// <exception cref="IOException">isotope configuration could not be loaded</exception> private static int?MassNumber(int atomicNumber, double exactMass) { var symbol = PeriodicTable.GetSymbol(atomicNumber); var isotope = CDK.IsotopeFactory.GetIsotope(symbol, exactMass, 0.001); return(isotope?.MassNumber); }
private BODRIsotopeFactory() { string configFile = "NCDK.Config.Data.isotopes.dat"; var ins = ResourceLoader.GetAsStream(configFile); var buffer = new byte[8]; ins.Read(buffer, 0, 4); Array.Reverse(buffer, 0, 4); int isotopeCount = BitConverter.ToInt32(buffer, 0); for (int i = 0; i < isotopeCount; i++) { var atomicNum = ins.ReadByte(); ins.Read(buffer, 0, 2); Array.Reverse(buffer, 0, 2); var massNum = BitConverter.ToInt16(buffer, 0); ins.Read(buffer, 0, 8); Array.Reverse(buffer, 0, 8); var exactMass = BitConverter.ToDouble(buffer, 0); double natAbund; if (ins.ReadByte() == 1) { ins.Read(buffer, 0, 8); Array.Reverse(buffer, 0, 8); natAbund = BitConverter.ToDouble(buffer, 0); } else { natAbund = 0; } var isotope = new BODRIsotope(PeriodicTable.GetSymbol(atomicNum), atomicNum, massNum, exactMass, natAbund); Add(isotope); } }
private void ProcessAtomsBlock(int lineCount, IAtomContainer container) { for (int i = 0; i < lineCount; i++) { string line = input.ReadLine(); int atomicNumber = int.Parse(line.Substring(7, 3).Trim(), NumberFormatInfo.InvariantInfo); IAtom atom = container.Builder.NewAtom(); atom.AtomicNumber = atomicNumber; atom.Symbol = PeriodicTable.GetSymbol(atomicNumber); container.Atoms.Add(atom); } }
private static bool ParseAtomSymbol(IAtom atom, string str) { int len = str.Length; int pos = 0; int mass = -1; int anum = 0; int hcnt = 0; int chg = 0; // optional mass if (pos < len && IsDigit(str[pos])) { mass = (str[pos++] - '0'); while (pos < len && IsDigit(str[pos])) { mass = 10 * mass + (str[pos++] - '0'); } } else { switch (str) { case "R": atom.AtomicNumber = 0; atom.Symbol = "R"; return(true); case "*": atom.AtomicNumber = 0; atom.Symbol = "*"; return(true); case "D": atom.AtomicNumber = 1; atom.MassNumber = 2; atom.Symbol = "H"; return(true); case "T": atom.AtomicNumber = 1; atom.MassNumber = 3; atom.Symbol = "H"; return(true); } } // atom symbol if (pos < len && IsUpper(str[pos])) { int beg = pos; pos++; while (pos < len && IsLower(str[pos])) { pos++; } anum = ChemicalElement.OfSymbol(str.Substring(beg, pos - beg)).AtomicNumber; if (anum == AtomicNumbers.Unknown) { return(false); } // optional fields after atom symbol while (pos < len) { switch (str[pos]) { case 'H': pos++; if (pos < len && IsDigit(str[pos])) { while (pos < len && IsDigit(str[pos])) { hcnt = 10 * hcnt + (str[pos++] - '0'); } } else { hcnt = 1; } break; case '+': pos++; if (pos < len && IsDigit(str[pos])) { chg = (str[pos++] - '0'); while (pos < len && IsDigit(str[pos])) { chg = 10 * chg + (str[pos++] - '0'); } } else { chg = +1; } break; case '-': pos++; if (pos < len && IsDigit(str[pos])) { chg = (str[pos++] - '0'); while (pos < len && IsDigit(str[pos])) { chg = 10 * chg + (str[pos++] - '0'); } chg *= -1; } else { chg = -1; } break; default: return(false); } } } else { return(false); } if (mass < 0) { atom.MassNumber = null; } else { atom.MassNumber = mass; } atom.AtomicNumber = anum; atom.Symbol = PeriodicTable.GetSymbol(anum); atom.ImplicitHydrogenCount = hcnt; atom.FormalCharge = chg; return(pos == len && len > 0); }
/// <summary> /// Reads a set of coordinates into ChemFrame. /// </summary> /// <param name="model"></param> private void ReadCoordinates(IChemModel model) { var moleculeSet = model.Builder.NewAtomContainerSet(); IAtomContainer molecule = model.Builder.NewAtomContainer(); string line = input.ReadLine(); line = input.ReadLine(); line = input.ReadLine(); line = input.ReadLine(); while (true) { line = input.ReadLine(); if ((line == null) || (line.Contains("-----"))) { break; } int atomicNumber; StringReader sr = new StringReader(line); StreamTokenizer token = new StreamTokenizer(sr); token.NextToken(); // ignore first token if (token.NextToken() == StreamTokenizer.TTypeNumber) { atomicNumber = (int)token.NumberValue; if (atomicNumber == 0) { // Skip dummy atoms. Dummy atoms must be skipped // if frequencies are to be read because Gaussian // does not report dummy atoms in frequencies, and // the number of atoms is used for reading frequencies. continue; } } else { throw new CDKException("Error while reading coordinates: expected integer."); } token.NextToken(); // ignore third token double x; double y; double z; if (token.NextToken() == StreamTokenizer.TTypeNumber) { x = token.NumberValue; } else { throw new IOException("Error reading x coordinate"); } if (token.NextToken() == StreamTokenizer.TTypeNumber) { y = token.NumberValue; } else { throw new IOException("Error reading y coordinate"); } if (token.NextToken() == StreamTokenizer.TTypeNumber) { z = token.NumberValue; } else { throw new IOException("Error reading z coordinate"); } string symbol = "Du"; symbol = PeriodicTable.GetSymbol(atomicNumber); IAtom atom = model.Builder.NewAtom(symbol); atom.Point3D = new Vector3(x, y, z); molecule.Atoms.Add(atom); } // this is the place where we store the atomcount to be used as a // counter in the nmr reading atomCount = molecule.Atoms.Count; moleculeSet.Add(molecule); model.MoleculeSet = moleculeSet; }