📄 modelbuilder3d.java
字号:
farthestVector.normalize(); farthestVector.scale((startAtomVector.length() + lengthFarthestAtomVector)); double dotProduct = farthestAtomVector.dot(farthestVector); double angle = Math.acos(dotProduct / (farthestAtomVector.length() * farthestVector.length())); Vector3d ringCenter = new Vector3d(); for (int i = 0; i < ac.getAtomCount(); i++) { if (!(ac.getAtom(i).getFlag(CDKConstants.ISPLACED))) { ringCenter.x = (ac.getAtom(i).getPoint3d()).x - newCoord.x; ringCenter.y = (ac.getAtom(i).getPoint3d()).y - newCoord.y; ringCenter.z = (ac.getAtom(i).getPoint3d()).z - newCoord.z; ringCenter = AtomTetrahedralLigandPlacer3D.rotate(ringCenter, n1, angle); ac.getAtom(i).setPoint3d( new Point3d( ringCenter.x + newCoord.x, ringCenter.y + newCoord.y, ringCenter.z + newCoord.z ) ); //ac.getAtomAt(i).setFlag(CDKConstants.ISPLACED, true); } } //Rotate Ring so that geometric center is max from placed center //logger.debug("Rotate RINGSYSTEM"); Point3d pointRingCenter = GeometryToolsInternalCoordinates.get3DCenter(ac); double distance = 0; double rotAngleMax = 0; angle = 1 / 180 * Math.PI; ringCenter = new Vector3d(pointRingCenter.x, pointRingCenter.y, pointRingCenter.z); ringCenter.x = ringCenter.x - newCoord.x; ringCenter.y = ringCenter.y - newCoord.y; ringCenter.z = ringCenter.z - newCoord.z; for (int i = 1; i < 360; i++) { ringCenter = AtomTetrahedralLigandPlacer3D.rotate(ringCenter, axis, angle); if (centerPlacedMolecule.distance(new Point3d(ringCenter.x, ringCenter.y, ringCenter.z)) > distance) { rotAngleMax = i; distance = centerPlacedMolecule.distance(new Point3d(ringCenter.x, ringCenter.y, ringCenter.z)); } } //rotate ring around axis with best angle rotAngleMax = (rotAngleMax / 180) * Math.PI; for (int i = 0; i < ac.getAtomCount(); i++) { if (!(ac.getAtom(i).getFlag(CDKConstants.ISPLACED))) { ringCenter.x = (ac.getAtom(i).getPoint3d()).x; ringCenter.y = (ac.getAtom(i).getPoint3d()).y; ringCenter.z = (ac.getAtom(i).getPoint3d()).z; ringCenter = AtomTetrahedralLigandPlacer3D.rotate(ringCenter, axis, rotAngleMax); ac.getAtom(i).setPoint3d( new Point3d( ringCenter.x, ringCenter.y, ringCenter.z ) ); ac.getAtom(i).setFlag(CDKConstants.ISPLACED, true); } } } private IAtomContainer getAllInOneContainer(IRingSet ringSet) { IAtomContainer resultContainer = ringSet.getBuilder().newAtomContainer(); Iterator containers = RingSetManipulator.getAllAtomContainers(ringSet).iterator(); while (containers.hasNext()) { resultContainer.add((IAtomContainer) containers.next()); } return resultContainer; } /** * Sets a branch atom to a ring or aliphatic chain * *@param unplacedAtom The new branchAtom *@param atomA placed atom to which the unplaced satom is connected *@param atomNeighbours placed atomNeighbours of atomA * @param ap3d * @param atlp3d *@exception Exception Description of the Exception */ private void setBranchAtom(IMolecule molecule, IAtom unplacedAtom, IAtom atomA, IAtomContainer atomNeighbours, AtomPlacer3D ap3d, AtomTetrahedralLigandPlacer3D atlp3d) throws Exception { //logger.debug("****** SET Branch Atom ****** >"+molecule.getAtomNumber(unplacedAtom)); IAtomContainer noCoords = new org.openscience.cdk.AtomContainer(); noCoords.addAtom(unplacedAtom); Point3d centerPlacedMolecule = ap3d.geometricCenterAllPlacedAtoms(molecule); IAtom atomB = atomNeighbours.getAtom(0); double length = ap3d.getBondLengthValue(atomA.getAtomTypeName(), unplacedAtom.getAtomTypeName()); double angle = (ap3d.getAngleValue(atomB.getAtomTypeName(), atomA.getAtomTypeName(), unplacedAtom.getAtomTypeName())) * Math.PI / 180; /* * System.out.println("A:"+atomA.getSymbol()+" "+atomA.getAtomTypeName()+" B:"+atomB.getSymbol()+" "+atomB.getAtomTypeName() * +" unplaced Atom:"+unplacedAtom.getAtomTypeName()+" BL:"+length+" Angle:"+angle * +" FormalNeighbour:"+atomA.getFormalNeighbourCount()+" HYB:"+atomA.getFlag(CDKConstants.HYBRIDIZATION_SP2) * +" #Neigbhours:"+atomNeighbours.getAtomCount()); */ IAtom atomC = ap3d.getPlacedHeavyAtom(molecule, atomB, atomA); Point3d[] branchPoints = atlp3d.get3DCoordinatesForLigands(atomA, noCoords, atomNeighbours, atomC , (atomA.getFormalNeighbourCount() - atomNeighbours.getAtomCount()) , length, angle); double distance = 0; int farthestPoint = 0; try { for (int i = 0; i < branchPoints.length; i++) { if (Math.abs(branchPoints[i].distance(centerPlacedMolecule)) > Math.abs(distance)) { distance = branchPoints[i].distance(centerPlacedMolecule); farthestPoint = i; } } } catch (Exception ex2) { throw new IOException("SetBranchAtomERROR: Not enough branch Points"); } int stereo = -1; if (atomA.getStereoParity() != 0 || (Math.abs((molecule.getBond(atomA, unplacedAtom)).getStereo()) < 2 && Math.abs((molecule.getBond(atomA, unplacedAtom)).getStereo()) != 0) && molecule.getMaximumBondOrder(atomA) < 1.5) { if (atomNeighbours.getAtomCount() > 1) { stereo = atlp3d.makeStereocenter(atomA.getPoint3d(), molecule.getBond(atomA, unplacedAtom), (atomNeighbours.getAtom(0)).getPoint3d(), (atomNeighbours.getAtom(1)).getPoint3d(), branchPoints); } } if (stereo != -1) { farthestPoint = stereo; } unplacedAtom.setPoint3d(branchPoints[farthestPoint]); unplacedAtom.setFlag(CDKConstants.ISPLACED, true); } /** * Search and place branches of a chain or ring * *@param chain AtomContainer if atoms in an aliphatic chain or ring system * @param ap3d * @param atlp3d * @param atomPlacer *@exception Exception Description of the Exception */ private void searchAndPlaceBranches(IMolecule molecule, IAtomContainer chain, AtomPlacer3D ap3d, AtomTetrahedralLigandPlacer3D atlp3d, AtomPlacer atomPlacer) throws Exception { //logger.debug("****** SEARCH AND PLACE ****** Chain length: "+chain.getAtomCount()); java.util.List atoms = null; IAtomContainer branchAtoms = new org.openscience.cdk.AtomContainer(); IAtomContainer connectedAtoms = new org.openscience.cdk.AtomContainer(); for (int i = 0; i < chain.getAtomCount(); i++) { atoms = molecule.getConnectedAtomsList(chain.getAtom(i)); for (int j = 0; j < atoms.size(); j++) { IAtom atom = (IAtom)atoms.get(j); if (!(atom.getSymbol()).equals("H") & !(atom.getFlag(CDKConstants.ISPLACED)) & !(atom.getFlag(CDKConstants.ISINRING))) { //logger.debug("SEARCH PLACE AND FOUND Branch Atom "+molecule.getAtomNumber(chain.getAtomAt(i))+ // " New Atom:"+molecule.getAtomNumber(atoms[j])+" -> STORE"); try { connectedAtoms.add(ap3d.getPlacedHeavyAtoms(molecule, chain.getAtom(i))); //logger.debug("Connected atom1:"+molecule.getAtomNumber(connectedAtoms.getAtomAt(0))+" atom2:"+ //molecule.getAtomNumber(connectedAtoms.getAtomAt(1))+ " Length:"+connectedAtoms.getAtomCount()); } catch (Exception ex1) { logger.error("SearchAndPlaceBranchERROR: Cannot find connected placed atoms due to" + ex1.toString()); throw new IOException("SearchAndPlaceBranchERROR: Cannot find connected placed atoms"); } try { setBranchAtom(molecule, atom, chain.getAtom(i), connectedAtoms, ap3d, atlp3d); } catch (Exception ex2) { logger.error("SearchAndPlaceBranchERROR: Cannot find enough neighbour atoms due to" + ex2.toString()); throw new CDKException("SearchAndPlaceBranchERROR: Cannot find enough neighbour atoms: " + ex2.getMessage(), ex2); } branchAtoms.addAtom(atom); connectedAtoms.removeAllElements(); } } }//for ac.getAtomCount placeLinearChains3D(molecule, branchAtoms, ap3d, atlp3d, atomPlacer); } /** * Layout all aliphatic chains with ZMatrix * *@param startAtoms AtomContainer of possible start atoms for a chain * @param ap3d * @param atlp3d * @param atomPlacer *@exception Exception Description of the Exception */ private void placeLinearChains3D(IMolecule molecule, IAtomContainer startAtoms, AtomPlacer3D ap3d, AtomTetrahedralLigandPlacer3D atlp3d, AtomPlacer atomPlacer) throws Exception { //logger.debug("****** PLACE LINEAR CHAINS ******"); IAtom dihPlacedAtom = null; IAtom thirdPlacedAtom = null; IAtomContainer longestUnplacedChain = new org.openscience.cdk.AtomContainer(); if (startAtoms.getAtomCount() == 0) { //no branch points ->linear chain //logger.debug("------ LINEAR CHAIN - FINISH ------"); } else { for (int i = 0; i < startAtoms.getAtomCount(); i++) { //logger.debug("FOUND BRANCHED ALKAN"); //logger.debug("Atom NOT NULL:" + molecule.getAtomNumber(startAtoms.getAtomAt(i))); thirdPlacedAtom = ap3d.getPlacedHeavyAtom(molecule, startAtoms.getAtom(i)); dihPlacedAtom = ap3d.getPlacedHeavyAtom(molecule, thirdPlacedAtom, startAtoms.getAtom(i)); longestUnplacedChain.addAtom(dihPlacedAtom); longestUnplacedChain.addAtom(thirdPlacedAtom); longestUnplacedChain.addAtom(startAtoms.getAtom(i)); longestUnplacedChain.add(atomPlacer.getLongestUnplacedChain(molecule, startAtoms.getAtom(i))); setAtomsToUnVisited(molecule); if (longestUnplacedChain.getAtomCount() < 4) { //di,third,sec //logger.debug("------ SINGLE BRANCH METHYLTYP ------"); //break; } else { //logger.debug("LongestUnchainLength:"+longestUnplacedChain.getAtomCount()); ap3d.placeAliphaticHeavyChain(molecule, longestUnplacedChain); ap3d.zmatrixChainToCartesian(molecule, true); searchAndPlaceBranches(molecule, longestUnplacedChain, ap3d, atlp3d, atomPlacer); } longestUnplacedChain.removeAllElements(); }//for } //logger.debug("****** HANDLE ALIPHATICS END ******"); } /** * Translates the template ring system to new coordinates * *@param originalCoord original coordinates of the placed ring atom from template *@param newCoord new coordinates from branch placement *@param ac AtomContainer contains atoms of ring system */ private void translateStructure(Point3d originalCoord, Point3d newCoord, IAtomContainer ac) { Point3d transVector = new Point3d(originalCoord); transVector.sub(newCoord); for (int i = 0; i < ac.getAtomCount(); i++) { if (!(ac.getAtom(i).getFlag(CDKConstants.ISPLACED))) { ac.getAtom(i).getPoint3d().sub(transVector); //ac.getAtomAt(i).setFlag(CDKConstants.ISPLACED, true); } } } /** * Returns the largest (number of atoms) ring set in a molecule * *@param ringSystems RingSystems of a molecule *@return The largestRingSet */ private IRingSet getLargestRingSet(List ringSystems) { IRingSet largestRingSet = null; int atomNumber = 0; IAtomContainer container = null; for (int i = 0; i < ringSystems.size(); i++) { container = getAllInOneContainer((IRingSet) ringSystems.get(i)); if (atomNumber < container.getAtomCount()) { atomNumber = container.getAtomCount(); largestRingSet = (IRingSet) ringSystems.get(i); } } return largestRingSet; } /** * Returns true if all atoms in an AtomContainer have coordinates * *@param ac AtomContainer *@return boolean */ private boolean checkAllRingAtomsHasCoordinates(IAtomContainer ac) { for (int i = 0; i < ac.getAtomCount(); i++) { if (ac.getAtom(i).getPoint3d() != null && ac.getAtom(i).getFlag(CDKConstants.ISINRING)) { } else if (!ac.getAtom(i).getFlag(CDKConstants.ISINRING)) { } else { return false; } } return true; } /** * Sets the atomsToPlace attribute of the ModelBuilder3D object * *@param ac The new atomsToPlace value */ private void setAtomsToPlace(IAtomContainer ac) { for (int i = 0; i < ac.getAtomCount(); i++) { ac.getAtom(i).setFlag(CDKConstants.ISPLACED, true); } } /** * Sets the atomsToUnPlaced attribute of the ModelBuilder3D object */ private void setAtomsToUnPlaced(IMolecule molecule) { for (int i = 0; i < molecule.getAtomCount(); i++) { molecule.getAtom(i).setFlag(CDKConstants.ISPLACED, false); } } /** * Sets the atomsToUnVisited attribute of the ModelBuilder3D object */ private void setAtomsToUnVisited(IMolecule molecule) { for (int i = 0; i < molecule.getAtomCount(); i++) { molecule.getAtom(i).setFlag(CDKConstants.VISITED, false); } } /** * Sets the templateHandler attribute of the ModelBuilder3D object * *@param templateHandler The new templateHandler value */ private void setTemplateHandler(TemplateHandler3D templateHandler) throws CDKException { if (templateHandler == null) throw new NullPointerException("The given template handler is null!"); this.templateHandler = templateHandler; } /** * Returns the number of loaded templates. Note that it may return 0 because * templates are lazy loaded, that is upon the first ring being layed out. * * @returns 0, if not templates are loaded */ public int getTemplateCount() { return this.templateHandler.getTemplateCount(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -