📄 atomcontainer.java
字号:
} return -1; } /** * Returns the position of the bond between two given atoms in the * electronContainers array. It returns -1 if the bond does not exist. * *@param atom1 The first atom *@param atom2 The second atom *@return The Position of the bond between a1 and a2 in the * electronContainers array. */ public int getBondNumber(IAtom atom1, IAtom atom2) { return (getBondNumber(getBond(atom1, atom2))); } /** * Returns the position of a given bond in the electronContainers array. It * returns -1 if the bond does not exist. * *@param bond The bond to be sought *@return The Position of the bond in the electronContainers array in [0,..]. */ public int getBondNumber(IBond bond) { for (int f = 0; f < bondCount; f++) { if (bonds[f] == bond) return f; } return -1; } /** * Returns the position of a given lone pair in the lone pair array. * It returns -1 if the lone pair does not exist. * *@param lonePair The lone pair to be sought *@return The Position of the lone pair in the array.. */ public int getLonePairNumber(ILonePair lonePair) { for (int f = 0; f < lonePairCount; f++) { if (lonePairs[f] == lonePair) return f; } return -1; } /** * Returns the position of a given single electron in the single electron array. * It returns -1 if the single electron does not exist. * *@param atom The single electron to be sought *@return The Position of the single electron in the array. */ public int getSingleElectronNumber(ISingleElectron singleElectron) { for (int f = 0; f < singleElectronCount; f++) { if (singleElectrons[f] == singleElectron) return f; } return -1; } /** * Returns the ElectronContainer at position <code>number</code> in the * container. * * @param number The position of the ElectronContainer to be returned. * @return The ElectronContainer at position <code>number</code>. */ public IElectronContainer getElectronContainer(int number) { if (number < this.bondCount) return bonds[number]; number -= this.bondCount; if (number < this.lonePairCount) return lonePairs[number]; number -= this.lonePairCount; if (number < this.singleElectronCount) return singleElectrons[number]; return null; } /** * Returns the bond that connectes the two given atoms. * * @param atom1 The first atom * @param atom2 The second atom * @return The bond that connectes the two atoms */ public IBond getBond(IAtom atom1, IAtom atom2) { for (int i = 0; i < getBondCount(); i++) { if (bonds[i].contains(atom1) && bonds[i].getConnectedAtom(atom1) == atom2) { return bonds[i]; } } return null; } /** * Returns the number of Atoms in this Container. * *@return The number of Atoms in this Container */ public int getAtomCount() { return this.atomCount; } /** * Returns the number of Bonds in this Container. * *@return The number of Bonds in this Container */ public int getBondCount() { return this.bondCount; } /** * Returns the number of LonePairs in this Container. * *@return The number of LonePairs in this Container */ public int getLonePairCount() { return this.lonePairCount; } /** * Returns the number of the single electrons in this container, * *@return The number of SingleElectron objects of this AtomContainer */ public int getSingleElectronCount() { return this.singleElectronCount; } /** * Returns the number of ElectronContainers in this Container. * * @return The number of ElectronContainers in this Container */ public int getElectronContainerCount() { return this.bondCount + this.lonePairCount + this.singleElectronCount; } /** * Returns an ArrayList of all atoms connected to the given atom. * *@param atom The atom the bond partners are searched of. *@return The ArrayList with the connected atoms */ public List getConnectedAtomsList(IAtom atom) { List atomsList = new ArrayList(); for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) atomsList.add(bonds[i].getConnectedAtom(atom)); } return atomsList; } /** * Returns an ArrayList of all Bonds connected to the given atom. * *@param atom The atom the connected bonds are searched of *@return The ArrayList with connected atoms */ public List getConnectedBondsList(IAtom atom) { List bondsList = new ArrayList(); for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) bondsList.add(bonds[i]); } return bondsList; } /** * Returns the array of lone pairs connected to an atom. * * @param atom The atom for which to get lone pairs * @return The array of LonePairs of this AtomContainer * @see #getElectronContainer * @see #electronContainers() * @see #getBond */ public List getConnectedLonePairsList(IAtom atom) { List lps = new ArrayList(); for (int i = 0; i < lonePairCount; i++) { if (lonePairs[i].contains(atom)) lps.add(lonePairs[i]); } return lps; } /** * Returns an array of all SingleElectron connected to the given atom. * *@param atom The atom on which the single electron is located *@return The array of SingleElectron of this AtomContainer */ public List getConnectedSingleElectronsList(IAtom atom) { List lps = new ArrayList(); for (int i = 0; i < singleElectronCount; i++) { if (singleElectrons[i].contains(atom)) lps.add(singleElectrons[i]); } return lps; } /** * Returns an ArrayList of all electronContainers connected to the given atom. * *@param atom The atom the connected electronContainers are searched of *@return The ArrayList with the connected atoms */ public List getConnectedElectronContainersList(IAtom atom) { List lps = new ArrayList(); for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) lps.add(bonds[i]); } for (int i = 0; i < lonePairCount; i++) { if (lonePairs[i].contains(atom)) lps.add(lonePairs[i]); } for (int i = 0; i < singleElectronCount; i++) { if (singleElectrons[i].contains(atom)) lps.add(singleElectrons[i]); } return lps; } /** * Returns the number of atoms connected to the given atom. * *@param atom The atom the number of bond partners are searched of. *@return The the size of connected atoms */ public int getConnectedAtomsCount(IAtom atom) { int count = 0; for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) ++count; } return count; } /** * Returns the number of Bonds for a given Atom. * *@param atom The atom *@return The number of Bonds for this atom */ public int getConnectedBondsCount(IAtom atom) { return getConnectedAtomsCount(atom); } /** * Returns the number of connected atoms (degree) to the given atom. * *@param atomNumber The atomnumber the degree is searched for *@return The number of connected atoms (degree) */ public int getConnectedBondsCount(int atomNumber) { return getConnectedAtomsCount(atoms[atomNumber]); } /** * Returns the number of LonePairs for a given Atom. * *@param atom The atom *@return The number of LonePairs for this atom */ public int getConnectedLonePairsCount(IAtom atom) { int count = 0; for (int i = 0; i < lonePairCount; i++) { if (lonePairs[i].contains(atom)) ++count; } return count; } /** * Returns the sum of the SingleElectron for a given Atom. * *@param atom The atom on which the single electron is located *@return The array of SingleElectron of this AtomContainer */ public int getConnectedSingleElectronsCount(IAtom atom) { int count = 0; for (int i = 0; i < singleElectronCount; i++) { if (singleElectrons[i].contains(atom)) ++count; } return count; } /** * Returns the sum of the bond orders for a given Atom. * * @param atom The atom * @return The number of bondorders for this atom */ public double getBondOrderSum(IAtom atom) { double count = 0; for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) count += bonds[i].getOrder(); } return count; } /** * Returns the maximum bond order that this atom currently has in the context * of this AtomContainer. * * @param atom The atom * @return The maximum bond order that this atom currently has */ public double getMaximumBondOrder(IAtom atom) { double max = 0.0; for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom) && bonds[i].getOrder() > max) { max = bonds[i].getOrder(); } } return max; } /** * Returns the minimum bond order that this atom currently has in the context * of this AtomContainer. * *@param atom The atom *@return The minimim bond order that this atom currently has */ public double getMinimumBondOrder(IAtom atom) { double min = 6; for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom) && bonds[i].getOrder() < min) { min = bonds[i].getOrder(); } } return min; } /** * Adds all atoms and electronContainers of a given atomcontainer to this * container. * *@param atomContainer The atomcontainer to be added */ public void add(IAtomContainer atomContainer) { for (int f = 0; f < atomContainer.getAtomCount(); f++) { if (!contains(atomContainer.getAtom(f))) { addAtom(atomContainer.getAtom(f)); } } for (int f = 0; f < atomContainer.getBondCount(); f++) { if (!contains(atomContainer.getBond(f))) { addBond(atomContainer.getBond(f)); } } for (int f = 0; f < atomContainer.getLonePairCount(); f++) { if (!contains(atomContainer.getLonePair(f))) { addLonePair(atomContainer.getLonePair(f)); } } for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) { if (!contains(atomContainer.getSingleElectron(f))) { addSingleElectron(atomContainer.getSingleElectron(f)); } } notifyChanged(); } /** * Adds the <code>ElectronContainer</code>s found in atomContainer to this * container. * *@param atomContainer AtomContainer with the new ElectronContainers */// public void addElectronContainers(IAtomContainer atomContainer)// {// // notifyChanged();// } /** * Adds an atom to this container. * *@param atom The atom to be added to this container */ public void addAtom(IAtom atom) { if (contains(atom)) { return; } if (atomCount + 1 >= atoms.length) { growAtomArray(); } atom.addListener(this); atoms[atomCount] = atom; atomCount++; notifyChanged(); } /** * Adds a Bond to this AtomContainer. * *@param bond The bond to added to this container */ public void addBond(IBond bond) { if (bondCount >= bonds.length) growBondArray(); bonds[bondCount] = bond; ++bondCount; notifyChanged(); } /** * Adds a lone pair to this AtomContainer. * *@param lonePair The LonePair to added to this container */ public void addLonePair(ILonePair lonePair) { if (lonePairCount >= lonePairs.length) growLonePairArray(); lonePairs[lonePairCount] = lonePair; ++lonePairCount; notifyChanged(); } /** * Adds a single electron to this AtomContainer. * *@param singleElectron The SingleElectron to added to this container */ public void addSingleElectron(ISingleElectron singleElectron) { if (singleElectronCount >= singleElectrons.length) growSingleElectronArray(); singleElectrons[singleElectronCount] = singleElectron; ++singleElectronCount; notifyChanged(); } /** * Adds a ElectronContainer to this AtomContainer. * *@param electronContainer The ElectronContainer to added to this container */ public void addElectronContainer(IElectronContainer electronContainer) { if (electronContainer instanceof IBond) this.addBond((IBond)electronContainer); if (electronContainer instanceof ILonePair) this.addLonePair((ILonePair)electronContainer); if (electronContainer instanceof ISingleElectron) this.addSingleElectron((ISingleElectron)electronContainer); } /** * Removes all atoms and electronContainers of a given atomcontainer from this * container. * *@param atomContainer The atomcontainer to be removed */ public void remove(IAtomContainer atomContainer) { for (int f = 0; f < atomContainer.getAtomCount(); f++) { removeAtom(atomContainer.getAtom(f)); } for (int f = 0; f < atomContainer.getBondCount(); f++) { removeBond(atomContainer.getBond(f)); } for (int f = 0; f < atomContainer.getLonePairCount(); f++) { removeLonePair(atomContainer.getLonePair(f)); } for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) { removeSingleElectron(atomContainer.getSingleElectron(f)); } } /** * Removes the atom at the given position from the AtomContainer. Note that * the electronContainers are unaffected: you also have to take care of * removing all electronContainers to this atom from the container manually. * *@param position The position of the atom to be removed. */ public void removeAtom(int position) { atoms[position].removeListener(this); for (int i = position; i < atomCount - 1; i++) { atoms[i] = atoms[i + 1]; } atoms[atomCount - 1] = null; atomCount--; notifyChanged(); } /** * Removes the given atom from the AtomContainer. Note that the * electronContainers are unaffected: you also have to take care of removeing * all electronContainers to this atom from the container. * *@param atom The atom to be removed */ public void removeAtom(IAtom atom) { int position = getAtomNumber(atom); if (position != -1) { removeAtom(position); } } /** * Removes the bond at the given position from the AtomContainer. * *@param position The position of the bond to be removed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -