public Isotope getIsotope(int massNumber) { Iterator<Isotope> isotopeIterator = isotopes.iterator(); Isotope isotope; while (isotopeIterator.hasNext()) { isotope = isotopeIterator.next(); if (isotope.getMassNumber() == massNumber) { return isotope; } } return null; }
public TreeSet<Isotope> getNaturallyOccuringIsotopes() { TreeSet<Isotope> isotopes = new TreeSet<>(); Iterator<Isotope> isotopeIterator = this.isotopes.iterator(); Isotope isotope; while (isotopeIterator.hasNext()) { isotope = isotopeIterator.next(); if (isotope.getAbundance() > 0) { isotopes.add(isotope); } } return isotopes; }
private Element( int atomicNumber, String name, String symbol, Collection<? extends Isotope> isotopes, Group group) { this.atomicNumber = atomicNumber; this.name = name; this.symbol = symbol; this.isotopes = new TreeSet<>(); for (Isotope isotope : isotopes) { this.isotopes.add(isotope.withElement(this)); } this.group = group; }
public double getMonoisotopicMass() { if (isotopes.isEmpty()) return 0; Iterator<Isotope> isotopeIterator = isotopes.iterator(); Isotope isotope; Isotope mostAbundant = isotopeIterator.next(); while (isotopeIterator.hasNext()) { isotope = isotopeIterator.next(); if (isotope.getAbundance() > mostAbundant.getAbundance()) { mostAbundant = isotope; } } return mostAbundant.getMass(); }
public double getVariance() { double average = getAverageMass(); double difference; double variance = 0; double totalAbundance = 0; Iterator<Isotope> isotopeIterator = isotopes.iterator(); Isotope isotope; while (isotopeIterator.hasNext()) { isotope = isotopeIterator.next(); difference = isotope.getMass() - average; variance += difference * difference * isotope.getAbundance(); totalAbundance += isotope.getAbundance(); } return variance / totalAbundance; }
public double getAverageMass() { double mass = 0; Iterator<Isotope> isotopeIterator = isotopes.iterator(); Isotope isotope; if (isNaturallyOccurring()) { while (isotopeIterator.hasNext()) { isotope = isotopeIterator.next(); mass += isotope.getMass() * isotope.getAbundance(); } return mass; } while (isotopeIterator.hasNext()) { isotope = isotopeIterator.next(); mass += isotope.getMass(); } return mass / isotopes.size(); }