Utility to determine if the specified mass is the major isotope for the given atomic number.

@param number atomic number
@param mass   atomic mass
@return the mass is the major mass for the atomic number
198292
private boolean isMajorIsotope(int number, int mass) {
        try {
            IIsotope isotope = Isotopes.getInstance().getMajorIsotope(number);
            return isotope != null && isotope.getMassNumber().equals(mass);
        } catch (IOException e) {
            return false;
        }
    }
1265558
public IMolecularFormulaSet generate(double mass) {

        if (mass <= 0.0) {
            logger.error("Proposed mass is not valid: ", mass);
            return null;
        }
        IMolecularFormula minimalMF = MolecularFormulaRangeManipulator.getMinimalFormula(mfRange, builder);
        IMolecularFormula maximalMF = MolecularFormulaRangeManipulator.getMaximalFormula(mfRange, builder);
        double massMim = MolecularFormulaManipulator.getTotalExactMass(minimalMF) - tolerance;
        double massMap = MolecularFormulaManipulator.getTotalExactMass(maximalMF) + tolerance;
        if (massMim > mass || massMap < mass) {
            logger.error("Proposed mass is out of the range: ", mass);
            return null;
        }

        IMolecularFormulaSet molecularFormulaSet = builder.newInstance(IMolecularFormulaSet.class);

        int[][] matrix = this.matrix_Base;
        int numberElements = mfRange.getIsotopeCount();

        // put IIsotope into a list
        List<IIsotope> isotopes_TO = new ArrayList<IIsotope>();
        Iterator<IIsotope> isIt = mfRange.isotopes().iterator();
        while (isIt.hasNext())
            isotopes_TO.add(isIt.next());

        isotopes_TO = orderList(isotopes_TO);

        for (int i = 0; i < matrix.length; i++) {

            /* constructing initial combinations */
            int[] value_In = new int[numberElements];
            for (int j = 0; j < numberElements; j++) {
                if (matrix[i][j] == 0)
                    value_In[j] = 0;
                else
                    value_In[j] = 1;
            }

            /* find number of element to combine */
            int count_E = 0;
            ArrayList<Integer> elem_Pos = new ArrayList<Integer>();
            for (int j = 0; j < matrix[1].length; j++)
                if (value_In[j] != 0) {
                    count_E++;
                    elem_Pos.add(j);
                }

            boolean flag = true;
            /* first position those first starting at the left */
            int possChan = 0;
            String lastMFString = "";
            while (flag) {

                //				// print all combinations --------------------------------------------------
                //				System.out.print(elem_Pos.get(possChan).intValue()+">");
                //				for(int j= 0 ; j< matrix[1].length; j++)
                //					System.out.print(isotopes_TO.get(j).getSymbol()+value_In[j]+"-");
                //				System.out.println();
                //				// print all combinations --------------------------------------------------

                // control if some of the element is contained. E.g. C(1-3)H(1-3)
                // the matrix 01 or 10 can not exist
                boolean flagBreak = false;
                for (int j = 0; j < matrix[1].length; j++) {
                    int min = mfRange.getIsotopeCountMin(isotopes_TO.get(j));
                    if (value_In[j] == 0) if (min != 0) flagBreak = true;
                }
                if (flagBreak) break;

                /*
                 * Find max occurence given a mass for a element with minimal
                 * elements
                 */
                int occurence = getMaxOccurence(mass, elem_Pos.get(possChan).intValue(), value_In, isotopes_TO);

                /* at least one */
                if (occurence == 0) break;

                int maxx = mfRange.getIsotopeCountMax(isotopes_TO.get(elem_Pos.get(possChan).intValue()));
                int minn = mfRange.getIsotopeCountMin(isotopes_TO.get(elem_Pos.get(possChan).intValue()));

                /* restriction of the number of max and min number for a element */
                if (occurence < minn | maxx < occurence) {
                    /*
                     * when is not in the occurrence that means that we have to
                     * restart one value to the predecessor.
                     */

                    if (possChan < elem_Pos.size() - 1) {
                        /* Means that is possible to fit the next */
                        if (maxx < occurence) value_In[elem_Pos.get(possChan).intValue()] = maxx;
                        possChan++;

                    } else {
                        boolean foundZ = false;
                        for (int z = possChan - 1; z >= 0; z--) {
                            if (value_In[elem_Pos.get(z).intValue()] != 1) {
                                possChan = z;
                                foundZ = true;
                                int newValue = value_In[elem_Pos.get(possChan).intValue()] - 1;

                                value_In[elem_Pos.get(possChan).intValue()] = newValue;
                                for (int j = possChan + 1; j < elem_Pos.size(); j++) {
                                    int p = elem_Pos.get(j).intValue();
                                    value_In[p] = 1;
                                }
                                possChan++;
                                break;
                            }
                        }
                        if (!foundZ) break;

                    }

                    continue;
                } /* final not occurrence */

                /* set the occurrence into the matrix */
                value_In[elem_Pos.get(possChan).intValue()] = occurence;

                double massT = calculateMassT(isotopes_TO, value_In);
                double diff_new = Math.abs(mass - (massT));

                if (diff_new < tolerance) {
                    IMolecularFormula myMF = getFormula(isotopes_TO, value_In);
                    String newMFString = MolecularFormulaManipulator.getString(myMF);

                    if (!newMFString.equals(lastMFString)) {
                        molecularFormulaSet.addMolecularFormula(myMF);
                        lastMFString = newMFString;
                    }
                }

                if (count_E == 1) /* only valid for the first random 1000 */
                break;

                if (possChan < elem_Pos.size() - 1) {
                    /* Means that is possible to fit the next */
                    //					value_In[elem_Pos.get(possChan).intValue()] = maxx;
                    possChan++;

                } else {
                    boolean foundZ = false;
                    for (int z = possChan - 1; z >= 0; z--) {
                        if (value_In[elem_Pos.get(z).intValue()] != 1) {
                            possChan = z;
                            foundZ = true;
                            int newValue = value_In[elem_Pos.get(possChan).intValue()] - 1;

                            value_In[elem_Pos.get(possChan).intValue()] = newValue;
                            for (int j = possChan + 1; j < elem_Pos.size(); j++) {
                                int p = elem_Pos.get(j).intValue();
                                value_In[p] = 1;
                            }
                            possChan++;
                            break;
                        }
                    }
                    if (!foundZ) break;

                }
            }

        }

        return returnOrdered(mass, molecularFormulaSet);
    }
1314843
public BigDecimal get(JcNumber number) {
		Object val = this.getFor(number);
		if (val != null)
			return (BigDecimal)val;
		return null;
	}
1267122
private int getAtomPosition(IAtom atom, IAtomContainer container) {
        for (int i = 0; i < container.getAtomCount(); i++) {
            if (atom.equals(container.getAtom(i))) {
                return i;
            }
        }
        return -1;
    }
632074
def center_of_mass(entity, geometric=False):
    
    
    # Structure, Model, Chain, Residue
    if isinstance(entity, Entity.Entity):
        atom_list = entity.get_atoms()
    # List of Residues, added 2018-03-17 by Nathan
    elif hasattr(entity, '__iter__') and [x for x in entity if x.level == 'R']:
        atom_list = []
        for res in entity:
            atom_list.extend(list(res.get_atoms()))
    # List of Atoms
    elif hasattr(entity, '__iter__') and [x for x in entity if x.level == 'A']:
        atom_list = entity
    else: # Some other weirdo object
        raise ValueError("Center of Mass can only be calculated from the following objects:\n"
                            "Structure, Model, Chain, Residue, list of Atoms.")
    
    masses = []
    positions = [ [], [], [] ] # [ [X1, X2, ..] , [Y1, Y2, ...] , [Z1, Z2, ...] ]
    
    for atom in atom_list:
        masses.append(atom.mass)
        
        for i, coord in enumerate(np.array(atom.coord).tolist()):
            positions[i].append(coord)

    # If there is a single atom with undefined mass complain loudly.
    if 'ukn' in set(masses) and not geometric:
        raise ValueError("Some Atoms don't have an element assigned.\n"
                         "Try adding them manually or calculate the geometrical center of mass instead.")
    
    if geometric:
        return [sum(coord_list)/len(masses) for coord_list in positions]
    else:       
        w_pos = [ [], [], [] ]
        for atom_index, atom_mass in enumerate(masses):
            w_pos[0].append(positions[0][atom_index]*atom_mass)
            w_pos[1].append(positions[1][atom_index]*atom_mass)
            w_pos[2].append(positions[2][atom_index]*atom_mass)

        return [sum(coord_list)/sum(masses) for coord_list in w_pos]
1157200
public static IMolecularFormula getMinimalFormula(MolecularFormulaRange mfRange, IChemObjectBuilder builder) {
        IMolecularFormula formula = builder.newInstance(IMolecularFormula.class);

        for (IIsotope isotope : mfRange.isotopes()) {
            formula.addIsotope(isotope, mfRange.getIsotopeCountMin(isotope));
        }

        return formula;
    }
1143590
@Override
    public boolean matches(IAtom atom) {
        return Preconditions.checkNotNull(atom.getAtomicNumber(), "Atomic number is not set.").equals(
                this.getAtomicNumber());
    }
791656
public boolean hasSameNumberAs(Number number) {
        checkNumber(number);
        try {
            return this.number == getInternalNumber(number, false);
        } catch (ArithmeticException e) {
            return false;
        }
    }
84416
@Override
    public DescriptorValue calculate(IAtomContainer mol) {
        try {
            mol = mol.clone();
        } catch (CloneNotSupportedException ex) {
        }
        double polar = 0, weight = 0;
        try {
            // type & assign implicit hydrogens
            IChemObjectBuilder builder = mol.getBuilder();
            CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(builder);
            for (IAtom atom : mol.atoms()) {
                IAtomType type = matcher.findMatchingAtomType(mol, atom);
                AtomTypeManipulator.configure(atom, type);
            }
            CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(builder);
            adder.addImplicitHydrogens(mol);

            // polar surface area: chain it off the TPSADescriptor
            TPSADescriptor tpsa = new TPSADescriptor();
            DescriptorValue value = tpsa.calculate(mol);
            polar = ((DoubleResult) value.getValue()).doubleValue();

            //  molecular weight
            for (IAtom atom : mol.atoms()) {
                weight += Isotopes.getInstance().getMajorIsotope(atom.getSymbol()).getExactMass();
                Integer hcount = atom.getImplicitHydrogenCount();
                if (hcount != CDKConstants.UNSET) weight += hcount * 1.00782504;
            }
        } catch (CDKException | IOException exception) {
            return getDummyDescriptorValue(exception);
        }

        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(
                weight == 0 ? 0 : polar / weight), getDescriptorNames());
    }
469138
private IIsotope getIsotope(IIsotope isotope) {
        for (Iterator<IIsotope> it = isotopes().iterator(); it.hasNext();) {
            IIsotope thisIsotope = it.next();
            if (isTheSame(isotope, thisIsotope)) return thisIsotope;
        }
        return null;
    }
389644
public ValueNumber forNumber(int number) {
        if (number >= getNumValuesAllocated()) {
            throw new IllegalArgumentException("Value " + number + " has not been allocated");
        }
        return allocatedValueList.get(number);
    }
805362
private static BigInteger getFactorial(int number) {
                BigInteger factorial = BigInteger.ONE;
                for (int i = number; i > 1; i--) {
                        factorial = factorial.multiply(new BigInteger(Integer.toString(i)));
                }
                return factorial;
        }
371994
public void removeIsotope(IIsotope isotope) {
        isotopesMax.remove(getIsotope(isotope));
        isotopesMin.remove(getIsotope(isotope));
    }
1060922
private static Object toNumber( String value)
    {
    Object number;

    try
      {
      number = toExternalNumber( new BigDecimal( value));
      }
    catch( Exception e)
      {
      number = null;
      }

    return number;
    }
597660
IAtom toCDKAtom(Atom beamAtom, int hCount) {

        IAtom cdkAtom = newCDKAtom(beamAtom);

        cdkAtom.setImplicitHydrogenCount(hCount);
        cdkAtom.setFormalCharge(beamAtom.charge());

        if (beamAtom.isotope() >= 0) cdkAtom.setMassNumber(beamAtom.isotope());

        if (beamAtom.aromatic()) cdkAtom.setIsAromatic(true);

        if (beamAtom.atomClass() > 0) cdkAtom.setProperty(ATOM_ATOM_MAPPING, beamAtom.atomClass());

        return cdkAtom;
    }
1294851
public void setMonoIsotope(IsotopeContainer isoContainer) {
        if (!isotopeCList.contains(isoContainer)) 
            isotopeCList.add(isoContainer);
        monoIsotopePosition = isotopeCList.indexOf(isoContainer);
    }
332450
public static boolean isValidDouble(String number) {
        boolean valid = false;
        if (isDouble(number) && isPositive(Double.parseDouble(number))) {
            valid = true;
        }
        return valid;
    }