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

📄 structurediagramgenerator.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			Vector2d translationVector = new Vector2d(oldPoint1);			translationVector.sub(new Vector2d(newPoint1));			/*			 * Move to fit old attachment bond orientation			 */			GeometryToolsInternalCoordinates.translate2D(ringSystem, translationVector);			/*			 * Rotate to fit old attachment bond orientation			 */			GeometryToolsInternalCoordinates.rotate(ringSystem, oldPoint1, angleDiff);			logger.debug("...done translating/rotating new ringset to fit old attachment bond orientation.");		}		else			logger.debug("...no bond found");		logger.debug("End of layoutNextRingSystem()");	}	/**	 *  Returns an AtomContainer with all unplaced atoms connected to a given	 *  atom	 *	 *  @param  atom  The Atom whose unplaced bonding partners are to be returned	 *  @return       an AtomContainer with all unplaced atoms connected to a	 *                given atom	 */	private IAtomContainer getUnplacedAtoms(IAtom atom)	{		IAtomContainer unplacedAtoms = atom.getBuilder().newAtomContainer();		java.util.List bonds = molecule.getConnectedBondsList(atom);		IAtom connectedAtom;		for (int f = 0; f < bonds.size(); f++)		{			connectedAtom = ((IBond)bonds.get(f)).getConnectedAtom(atom);			if (!connectedAtom.getFlag(CDKConstants.ISPLACED))			{				unplacedAtoms.addAtom(connectedAtom);			}		}		return unplacedAtoms;	}	/**	 *  Returns an AtomContainer with all placed atoms connected to a given	 *  atom	 *	 *  @param  atom  The Atom whose placed bonding partners are to be returned	 *  @return       an AtomContainer with all placed atoms connected to a given	 *                atom	 */	private IAtomContainer getPlacedAtoms(IAtom atom)	{		IAtomContainer placedAtoms = atom.getBuilder().newAtomContainer();		java.util.List bonds = molecule.getConnectedBondsList(atom);		IAtom connectedAtom;		for (int f = 0; f < bonds.size(); f++)		{			connectedAtom = ((IBond)bonds.get(f)).getConnectedAtom(atom);			if (connectedAtom.getFlag(CDKConstants.ISPLACED))			{				placedAtoms.addAtom(connectedAtom);			}		}		return placedAtoms;	}	/**	 *  Returns the next atom with unplaced aliphatic neighbors	 *	 *  @return    the next atom with unplaced aliphatic neighbors	 */	private IAtom getNextAtomWithAliphaticUnplacedNeigbors()	{		IBond bond;		for (int f = 0; f < molecule.getBondCount(); f++)		{			bond = molecule.getBond(f);						if (bond.getAtom(1).getFlag(CDKConstants.ISPLACED) &&				!bond.getAtom(0).getFlag(CDKConstants.ISPLACED))			{				return bond.getAtom(1);			}			if (bond.getAtom(0).getFlag(CDKConstants.ISPLACED) &&				!bond.getAtom(1).getFlag(CDKConstants.ISPLACED))			{				return bond.getAtom(0);			}		}		return null;	}	/**	 *  Returns the next bond with an unplaced ring atom	 *	 *  @return    the next bond with an unplaced ring atom	 */	private IBond getNextBondWithUnplacedRingAtom() {		Iterator bonds = molecule.bonds();		while (bonds.hasNext()) {			IBond bond = (IBond) bonds.next();			if (bond.getAtom(0).getPoint2d() != null &&					bond.getAtom(1).getPoint2d() != null) {				if (bond.getAtom(1).getFlag(CDKConstants.ISPLACED) &&						!bond.getAtom(0).getFlag(CDKConstants.ISPLACED) &&						bond.getAtom(0).getFlag(CDKConstants.ISINRING)) {					return bond;				}				if (bond.getAtom(0).getFlag(CDKConstants.ISPLACED) &&						!bond.getAtom(1).getFlag(CDKConstants.ISPLACED) &&						bond.getAtom(1).getFlag(CDKConstants.ISINRING)) {					return bond;				}			}		}		return null;	}	/**	 *  Places the first bond of the first ring such that one atom is at (0,0) and	 *  the other one at the position given by bondVector	 *	 *  @param  bondVector  A 2D vector to point to the position of the second bond	 *                      atom	 *  @param  bond        the bond to lay out	 *  @return             an IAtomContainer with the atoms of the bond and the bond itself	 */	private IAtomContainer placeFirstBond(IBond bond, Vector2d bondVector)	{		IAtomContainer sharedAtoms = null;		try		{			bondVector.normalize();			logger.debug("placeFirstBondOfFirstRing->bondVector.length():" + bondVector.length());			bondVector.scale(bondLength);			logger.debug("placeFirstBondOfFirstRing->bondVector.length() after scaling:" + bondVector.length());			IAtom atom;			Point2d point = new Point2d(0, 0);			atom = bond.getAtom(0);			logger.debug("Atom 1 of first Bond: " + (molecule.getAtomNumber(atom) + 1));			atom.setPoint2d(point);			atom.setFlag(CDKConstants.ISPLACED, true);			point = new Point2d(0, 0);			atom = bond.getAtom(1);			logger.debug("Atom 2 of first Bond: " + (molecule.getAtomNumber(atom) + 1));			point.add(bondVector);			atom.setPoint2d(point);			atom.setFlag(CDKConstants.ISPLACED, true);			/*			 *  The new ring is layed out relativ to some shared atoms that have already been			 *  placed. Usually this is another ring, that has already been draw and to which the new			 *  ring is somehow connected, or some other system of atoms in an aliphatic chain.			 *  In this case, it's the first bond that we layout by hand.			 */			sharedAtoms = atom.getBuilder().newAtomContainer();			sharedAtoms.addBond(bond);			sharedAtoms.addAtom(bond.getAtom(0));			sharedAtoms.addAtom(bond.getAtom(1));		} catch (Exception exc) {			logger.debug(exc);		}		return sharedAtoms;	}	/**	 *  This method will go as soon as the rest works. It just assignes Point2d's	 *  of position (0,0) so that the molecule can be drawn.	 */	private void fixRest()	{		IAtom atom = null;		for (int f = 0; f < molecule.getAtomCount(); f++)		{			atom = molecule.getAtom(f);			if (atom.getPoint2d() == null)			{				atom.setPoint2d(new Point2d(0, 0));			}		}	}	/**	 *  This method will go as soon as the rest works. It just assignes Point2d's	 *  of position (0,0) so that the molecule can be drawn.	 *  @param molecule the molecule to fix	 *  @return the fixed molecule	 */	private IMolecule fixMol(IMolecule molecule)	{		IAtom atom = null;		for (int f = 0; f < molecule.getAtomCount(); f++)		{			atom = molecule.getAtom(f);			if (atom.getPoint2d() == null)			{				atom.setPoint2d(new Point2d(0, 0));			}		}								return molecule;	}        	/**	 *  Initializes all rings in RingSet rs as not placed	 *	 *  @param  rs  The RingSet to be initialized	 *///	private void markNotPlaced(IRingSet rs)//	{//		for (int f = 0; f < rs.size(); f++)//		{//			((IRing) rs.get(f)).setFlag(CDKConstants.ISPLACED, false);//		}//	}	/**	 *  Are all rings in the Vector placed?	 *	 *  @param  rings  The Vector to be checked	 *  @return        true if all rings are placed, false otherwise	 */	private boolean allPlaced(IRingSet rings)	{		for (int f = 0; f < rings.getAtomContainerCount(); f++)		{			if (!((IRing) rings.getAtomContainer(f)).getFlag(CDKConstants.ISPLACED))			{				logger.debug("allPlaced->Ring " + f + " not placed");				return false;			}		}		return true;	}	/**	 *  Mark all atoms in the molecule as being part of a ring	 *	 *  @param  rings  an IRingSet with the rings to process	 */	private void markRingAtoms(IRingSet rings)	{		IRing ring = null;		for (int i = 0; i < rings.getAtomContainerCount(); i++)		{			ring = (IRing) rings.getAtomContainer(i);			for (int j = 0; j < ring.getAtomCount(); j++)			{				ring.getAtom(j).setFlag(CDKConstants.ISINRING, true);			}		}	}	/**	 *  Get the unplaced ring atom in this bond	 *	 *  @param  bond  the bond to be search for the unplaced ring atom	 *  @return       the unplaced ring atom in this bond	 */	private IAtom getRingAtom(IBond bond)	{		if (bond.getAtom(0).getFlag(CDKConstants.ISINRING) &&				!bond.getAtom(0).getFlag(CDKConstants.ISPLACED))		{			return bond.getAtom(0);		}		if (bond.getAtom(1).getFlag(CDKConstants.ISINRING) &&				!bond.getAtom(1).getFlag(CDKConstants.ISPLACED))		{			return bond.getAtom(1);		}		return null;	}	/**	 *  Get the ring system of which the given atom is part of	 *	 *  @param  ringSystems  a List of ring systems to be searched	 *  @param  ringAtom     the ring atom to be search in the ring system.	 *  @return              the ring system the given atom is part of	 */	private IRingSet getRingSystemOfAtom(List ringSystems, IAtom ringAtom)	{		IRingSet ringSet = null;		for (int f = 0; f < ringSystems.size(); f++)		{			ringSet = (IRingSet) ringSystems.get(f);			if (ringSet.contains(ringAtom))			{				return ringSet;			}		}		return null;	}	/**	 *  Set all the atoms in unplaced rings to be unplaced	 */	private void resetUnplacedRings()	{		IRing ring = null;		if (sssr == null)		{			return;		}		int unplacedCounter = 0;		for (int f = 0; f < sssr.getAtomContainerCount(); f++)		{			ring = (IRing) sssr.getAtomContainer(f);			if (!ring.getFlag(CDKConstants.ISPLACED))			{				logger.debug("Ring with " + ring.getAtomCount() + " atoms is not placed.");				unplacedCounter++;				for (int g = 0; g < ring.getAtomCount(); g++)				{					ring.getAtom(g).setFlag(CDKConstants.ISPLACED, false);				}			}		}		logger.debug("There are " + unplacedCounter + " unplaced Rings.");	}	/**	 *  Set the bond length used for laying out the molecule.	 *  The defaut value is 1.5.	 *	 *  @param  bondLength  The new bondLength value	 */	public void setBondLength(double bondLength)	{		this.bondLength = bondLength;	}					/**	 * Returns the other atom of the bond.	 * Expects bond to have only two atoms.	 * Returns null if the given atom is not part of the given bond.	 * 	 * @param atom the atom we already have	 * @param bond the bond	 * @return the other atom of the bond	 */	public IAtom getOtherBondAtom(IAtom atom, IBond bond) {		if (!bond.contains(atom))			return null;		if (bond.getAtom(0).equals(atom))			return bond.getAtom(1);		else			return bond.getAtom(0);	}}

⌨️ 快捷键说明

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