⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atomcontainer.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 */	public IBond removeBond(int position)	{		IBond bond = bonds[position];		bond.removeListener(this);		for (int i = position; i < bondCount - 1; i++)		{			bonds[i] = bonds[i + 1];		}		bonds[bondCount - 1] = null;		bondCount--;		notifyChanged();		return bond;	}		/**	 * Removes the bond that connects the two given atoms.	 *	 * @param  atom1  The first atom	 * @param  atom2  The second atom	 * @return        The bond that connectes the two atoms	 */	public IBond removeBond(IAtom atom1, IAtom atom2)	{		int pos = getBondNumber(atom1, atom2);		IBond bond = null;		if (pos != -1) {			bond = bonds[pos];			removeBond(pos);		}		return bond;	}		/**	 * Removes the bond from this container.	 *	 * @param  bond   The bond to be removed.	 */	public void removeBond(IBond bond)	{		int pos = getBondNumber(bond);		if (pos != -1) removeBond(pos);	}		/**	 *  Removes the lone pair at the given position from the AtomContainer.	 *	 *@param  position  The position of the LonePair to be removed.	 */	public ILonePair removeLonePair(int position)	{		ILonePair lp = lonePairs[position];		lp.removeListener(this);		for (int i = position; i < lonePairCount - 1; i++)		{			lonePairs[i] = lonePairs[i + 1];		}		lonePairs[lonePairCount - 1] = null;		lonePairCount--;		notifyChanged();		return lp;	}		/**	 *  Removes the lone pair from the AtomContainer.	 *	 *@param  lonePair  The LonePair to be removed.	 */	public void removeLonePair(ILonePair lonePair)	{		int pos = getLonePairNumber(lonePair);		if (pos != -1) removeLonePair(pos);	}		/**	 *  Removes the single electron at the given position from the AtomContainer.	 *	 *@param  position  The position of the SingleElectron to be removed.	 */	public ISingleElectron removeSingleElectron(int position)	{		ISingleElectron se = singleElectrons[position];		se.removeListener(this);		for (int i = position; i < singleElectronCount - 1; i++)		{			singleElectrons[i] = singleElectrons[i + 1];		}		singleElectrons[singleElectronCount - 1] = null;		singleElectronCount--;		notifyChanged();		return se;	}		/**	 *  Removes the single electron from the AtomContainer.	 *	 *@param  singleElectron  The SingleElectron to be removed.	 */	public void removeSingleElectron(ISingleElectron singleElectron)	{		int pos = getSingleElectronNumber(singleElectron);		if (pos != -1) removeSingleElectron(pos);	}		/**	 * Removes the bond at the given position from this container.	 *	 * @param  number  The position of the bond in the electronContainers array	 * @return           Bond that was removed	 */	public IElectronContainer removeElectronContainer(int number)	{		if (number < this.bondCount) return removeBond(number);		number -= this.bondCount;		if (number < this.lonePairCount) return removeLonePair(number);		number -= this.lonePairCount;		if (number < this.singleElectronCount) return removeSingleElectron(number);		return null;	}    /**     * Removes this ElectronContainer from this container.     *     * @param electronContainer The electronContainer to be removed     */    public void removeElectronContainer(IElectronContainer electronContainer) {        if (electronContainer instanceof IBond) removeBond((IBond) electronContainer);        else if (electronContainer instanceof ILonePair) removeLonePair((ILonePair) electronContainer);        else        if (electronContainer instanceof ISingleElectron) removeSingleElectron((ISingleElectron) electronContainer);	}	/**	 *  Removes the given atom and all connected electronContainers from the	 *  AtomContainer.	 *	 *@param  atom  The atom to be removed	 */	public void removeAtomAndConnectedElectronContainers(IAtom atom)	{		int position = getAtomNumber(atom);		if (position != -1)		{			for (int i = 0; i < bondCount; i++)			{				if (bonds[i].contains(atom)) {					removeBond(i);					--i;				}			}			for (int i = 0; i < lonePairCount; i++)			{				if (lonePairs[i].contains(atom)) {					removeLonePair(i);					--i;				}			}			for (int i = 0; i < singleElectronCount; i++)			{				if (singleElectrons[i].contains(atom)) {					removeSingleElectron(i);					--i;				}			}			removeAtom(position);		}		notifyChanged();	}	/**	 * Removes all atoms and bond from this container.	 */	public void removeAllElements() {		removeAllElectronContainers();        for (int f = 0; f < getAtomCount(); f++) {			getAtom(f).removeListener(this);			}        atoms = new IAtom[growArraySize];        atomCount = 0;		notifyChanged();	}	/**	 *  Removes electronContainers from this container.	 */	public void removeAllElectronContainers()	{		removeAllBonds();		for (int f = 0; f < getLonePairCount(); f++) {			getLonePair(f).removeListener(this);			}		for (int f = 0; f < getSingleElectronCount(); f++) {			getSingleElectron(f).removeListener(this);			}		lonePairs = new ILonePair[growArraySize];		singleElectrons = new ISingleElectron[growArraySize];		lonePairCount = 0;		singleElectronCount = 0;		notifyChanged();	}    /**     *  Removes all Bonds from this container.     */    public void removeAllBonds() {    	for (int f = 0; f < getBondCount(); f++) {			getBond(f).removeListener(this);			}    	bonds = new IBond[growArraySize];    	bondCount = 0;    	notifyChanged();    }	/**	 *  Adds a bond to this container.	 *	 *@param  atom1   Id of the first atom of the Bond in [0,..]	 *@param  atom2   Id of the second atom of the Bond in [0,..]	 *@param  order   Bondorder	 *@param  stereo  Stereochemical orientation	 */	public void addBond(int atom1, int atom2, double order, int stereo)	{		IBond bond = getBuilder().newBond(getAtom(atom1), getAtom(atom2), order, stereo);		if (contains(bond))		{			return;		}		if (bondCount >= bonds.length)		{			growBondArray();		}		addBond(bond);		/* no notifyChanged() here because addBond(bond) does 		   it already */	}	/**	 *  Adds a bond to this container.	 *	 *@param  atom1  Id of the first atom of the Bond in [0,..]	 *@param  atom2  Id of the second atom of the Bond in [0,..]	 *@param  order  Bondorder	 */	public void addBond(int atom1, int atom2, double order)	{		IBond bond = getBuilder().newBond(getAtom(atom1), getAtom(atom2), order);		if (bondCount >= bonds.length)		{			growBondArray();		}		addBond(bond);		/* no notifyChanged() here because addBond(bond) does 		   it already */	}	/**	 *  Adds a LonePair to this Atom.	 *	 *@param  atomID  The atom number to which the LonePair is added in [0,..]	 */	public void addLonePair(int atomID)	{		ILonePair lonePair = getBuilder().newLonePair(atoms[atomID]);		lonePair.addListener(this);		addLonePair(lonePair);		/* no notifyChanged() here because addElectronContainer() does 		   it already */	}		/**	 *  Adds a LonePair to this Atom.	 *	 *@param  atomID  The atom number to which the LonePair is added in [0,..]	 */	public void addSingleElectron(int atomID)	{		ISingleElectron singleElectron = getBuilder().newSingleElectron(atoms[atomID]);		singleElectron.addListener(this);		addSingleElectron(singleElectron);		/* no notifyChanged() here because addSingleElectron() does 		   it already */	}	/**	 *  True, if the AtomContainer contains the given atom object.	 *	 *@param  atom  the atom this AtomContainer is searched for	 *@return       True, if the AtomContainer contains the given atom object	 */	public boolean contains(IAtom atom)	{		for (int i = 0; i < getAtomCount(); i++)		{			if (atom == atoms[i]) return true;		}		return false;	}		/**	 *  True, if the AtomContainer contains the given bond object.	 *	 *@param  bond  the bond this AtomContainer is searched for	 *@return       True, if the AtomContainer contains the given bond object	 */	public boolean contains(IBond bond)	{		for (int i = 0; i < getBondCount(); i++)		{			if (bond == bonds[i]) return true;		}		return false;	}		/**	 *  True, if the AtomContainer contains the given LonePair object.	 *	 *@param  lonePair  the LonePair this AtomContainer is searched for	 *@return           True, if the AtomContainer contains the given LonePair object	 */	public boolean contains(ILonePair lonePair)	{		for (int i = 0; i < getLonePairCount(); i++)		{			if (lonePair == lonePairs[i]) return true;		}		return false;	}		/**	 *  True, if the AtomContainer contains the given SingleElectron object.	 *	 *@param  singleElectron  the LonePair this AtomContainer is searched for	 *@return           True, if the AtomContainer contains the given LonePair object	 */	public boolean contains(ISingleElectron singleElectron)	{		for (int i = 0; i < getSingleElectronCount(); i++)		{			if (singleElectron == singleElectrons[i]) return true;		}		return false;	}		/**	 *  True, if the AtomContainer contains the given ElectronContainer object.	 *	 *@param  electronContainer ElectronContainer that is searched for	 *@return                   True, if the AtomContainer contains the given bond object	 */	public boolean contains(IElectronContainer electronContainer)	{		if (electronContainer instanceof IBond) return contains((IBond)electronContainer);		if (electronContainer instanceof ILonePair) return contains((ILonePair)electronContainer);		if (electronContainer instanceof ISingleElectron) return contains((SingleElectron)electronContainer);		return false;	}		/**	 *  Returns a one line string representation of this Container. This method is	 *  conform RFC #9.	 *	 *@return    The string representation of this Container	 */	public String toString()	{		StringBuffer stringContent = new StringBuffer(64);		stringContent.append("AtomContainer(");		stringContent.append(this.hashCode());		stringContent.append(", #A:").append(getAtomCount());		stringContent.append(", #B:").append(getBondCount()).append(", ");		stringContent.append(", #LP:").append(getLonePairCount()).append(", ");		stringContent.append(", #SE:").append(getSingleElectronCount()).append(", ");		for (int i = 0; i < getAtomCount(); i++)		{			stringContent.append(getAtom(i).toString()).append(", ");		}		for (int i = 0; i < getBondCount(); i++)		{			stringContent.append(getBond(i).toString()).append(", ");		}		for (int i = 0; i < getLonePairCount(); i++)		{			stringContent.append(getLonePair(i).toString()).append(", ");		}		for (int i = 0; i < getSingleElectronCount(); i++)		{			stringContent.append(getSingleElectron(i).toString()).append(", ");		}		        stringContent.append(", AP:[#").append(atomParities.size()).append(", ");        Enumeration parities = atomParities.elements();        while (parities.hasMoreElements()) {			stringContent.append(parities.nextElement().toString());            if (parities.hasMoreElements()) stringContent.append(", ");		}		stringContent.append("])");		return stringContent.toString();	}	/**	 * Clones this AtomContainer object and its content.	 *	 * @return    The cloned object	 * @see       #shallowCopy	 */	public Object clone() throws CloneNotSupportedException {		IAtom[] newAtoms;		IAtomContainer clone = (IAtomContainer) super.clone();        // start from scratch		clone.removeAllElements();        // clone all atoms		for (int f = 0; f < getAtomCount(); f++) {			clone.addAtom((Atom) getAtom(f).clone());		}        // clone bonds		IBond bond;		IBond newBond;		for (int i = 0; i < getBondCount(); ++i) {			bond = getBond(i);			newBond = (IBond)bond.clone();			newAtoms = new IAtom[bond.getAtomCount()];			for (int j = 0; j < bond.getAtomCount(); ++j) {				newAtoms[j] = clone.getAtom(getAtomNumber(bond.getAtom(j)));			}			newBond.setAtoms(newAtoms);			clone.addBond(newBond);		}		ILonePair lp;		ILonePair newLp;		for (int i = 0; i < getLonePairCount(); ++i) {			lp = getLonePair(i);			newLp = (ILonePair)lp.clone();			newLp.setAtom(clone.getAtom(getAtomNumber(lp.getAtom())));			clone.addLonePair(newLp);		}		ISingleElectron se;		ISingleElectron newSe;		for (int i = 0; i < getSingleElectronCount(); ++i) {			se = getSingleElectron(i);			newSe = (ISingleElectron)se.clone();			newSe.setAtom(clone.getAtom(getAtomNumber(se.getAtom())));			clone.addSingleElectron(newSe);		}//		for (int f = 0; f < getElectronContainerCount(); f++) {//			electronContainer = this.getElectronContainer(f);//			newEC = getBuilder().newElectronContainer();//			if (electronContainer instanceof IBond) {//				IBond bond = (IBond) electronContainer;//				newEC = (IElectronContainer)bond.clone();//				newAtoms = new IAtom[bond.getAtomCount()];//				for (int g = 0; g < bond.getAtomCount(); g++) {//					newAtoms[g] = clone.getAtom(getAtomNumber(bond.getAtom(g)));//				}//				((IBond) newEC).setAtoms(newAtoms);//			} else if (electronContainer instanceof ILonePair) {//				IAtom atom = ((ILonePair) electronContainer).getAtom();//				newEC = (ILonePair)electronContainer.clone();//				((ILonePair) newEC).setAtom(clone.getAtom(getAtomNumber(atom)));//            } else if (electronContainer instanceof ISingleElectron) {//            	IAtom atom = ((ISingleElectron) electronContainer).getAtom();//                newEC = (ISingleElectron)electronContainer.clone();//                ((ISingleElectron) newEC).setAtom(clone.getAtom(getAtomNumber(atom)));//			} else {//				//logger.debug("Expecting EC, got: " + electronContainer.getClass().getName());//				newEC = (IElectronContainer) electronContainer.clone();//			}//			clone.addElectronContainer(newEC);//		}		return clone;	}	/**	 *  Grows the ElectronContainer array by a given size.	 *	 *@see    #growArraySize	 *///	protected void growElectronContainerArray()//	{//		growArraySize = (electronContainers.length < growArraySize) ? growArraySize : electronContainers.length;//		IElectronContainer[] newelectronContainers = new IElectronContainer[electronContainers.length + growArraySize];//		System.arraycopy(electronContainers, 0, newelectronContainers, 0, electronContainers.length);//		electronContainers = newelectronContainers;//	}	/**	 *  Grows the atom array by a given size.	 *	 *@see    #growArraySize	 */	protected void growAtomArray()	{		growArraySize = (atoms.length < growArraySize) ? growArraySize : atoms.length;		IAtom[] newatoms = new IAtom[atoms.length + growArraySize];		System.arraycopy(atoms, 0, newatoms, 0, atoms.length);		atoms = newatoms;	}		/**	 *  Grows the bond array by a given size.	 *	 *@see    #growArraySize	 */	protected void growBondArray()	{		growArraySize = (bonds.length < growArraySize) ? growArraySize : bonds.length;		IBond[] newBonds = new IBond[bonds.length + growArraySize];		System.arraycopy(bonds, 0, newBonds, 0, bonds.length);		bonds = newBonds;	}		/**	 *  Grows the lone pair array by a given size.	 *	 *@see    #growArraySize	 */	protected void growLonePairArray()	{		growArraySize = (lonePairs.length < growArraySize) ? growArraySize : lonePairs.length;		ILonePair[] newLonePairs = new ILonePair[lonePairs.length + growArraySize];		System.arraycopy(lonePairs, 0, newLonePairs, 0, lonePairs.length);		lonePairs = newLonePairs;	}		/**	 *  Grows the single electron array by a given size.	 *	 *@see    #growArraySize	 */	protected void growSingleElectronArray()	{		growArraySize = (singleElectrons.length < growArraySize) ? growArraySize : singleElectrons.length;		ISingleElectron[] newSingleElectrons = new ISingleElectron[singleElectrons.length + growArraySize];		System.arraycopy(singleElectrons, 0, newSingleElectrons, 0, singleElectrons.length);		singleElectrons = newSingleElectrons;	}		 /**	 *  Called by objects to which this object has	 *  registered as a listener.	 *	 *@param  event  A change event pointing to the source of the change	 */	public void stateChanged(IChemObjectChangeEvent event)	{		notifyChanged(event);	}   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -