com.actelion.research.chem.conf.AtomAssembler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openchemlib Show documentation
Show all versions of openchemlib Show documentation
Open Source Chemistry Library
/*
* Copyright (c) 1997 - 2016
* Actelion Pharmaceuticals Ltd.
* Gewerbestrasse 16
* CH-4123 Allschwil, Switzerland
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Thomas Sander
*/
package com.actelion.research.chem.conf;
import com.actelion.research.chem.Coordinates;
import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.StereoMolecule;
public class AtomAssembler {
private StereoMolecule mMol;
public AtomAssembler(StereoMolecule mol) {
mMol = mol;
}
public int addImplicitHydrogens() {
mMol.ensureHelperArrays(Molecule.cHelperRings);
int total = 0;
for (int atom=0; atom Math.PI)
dihedral -= 2*Math.PI;
addAtomWithConstraints(mMol.getCoordinates(atomSequence[0]), mMol.getCoordinates(atomSequence[1]),
mMol.getCoordinates(atomSequence[2]), atom, 1, angle, dihedral, length);
if (count != 1) {
dihedral += Math.PI*2/3;
if (dihedral > Math.PI)
dihedral -= 2*Math.PI;
addAtomWithConstraints(mMol.getCoordinates(atomSequence[0]), mMol.getCoordinates(atomSequence[1]),
mMol.getCoordinates(atomSequence[2]), atom, 1, angle, dihedral, length);
}
return count;
}
}
}
// no competing atoms
// if we have a single bonded option for atomSequence[0], then take that
for (int i=i0+1; inewAtom, angle c2->c3->newAtom and dihedral c1->c2->c3->newAtom are met.
* @param c1
* @param c2
* @param c3
* @param rootAtom
* @param angle
* @param dihedral
* @param bondLength
*/
private void addAtomWithConstraints(Coordinates c1, Coordinates c2, Coordinates c3, int rootAtom, int atomicNo, double angle, double dihedral, double bondLength) {
double r = bondLength * Math.sin(Math.PI - angle);
double x = -r * Math.sin(dihedral);
double y = r * Math.cos(dihedral);
double z = bondLength * Math.cos(Math.PI - angle);
Coordinates axisZ = c3.subC(c2).unit();
Coordinates axisX = c1.subC(c2).cross(axisZ).unit(); // needs to be mapped to x-axis
Coordinates axisY = axisX.cross(axisZ).unit(); // needs to be mapped to y-axis
double[][] m = new double[3][3];
m[0][0] = -axisX.x;
m[0][1] = -axisX.y;
m[0][2] = -axisX.z;
m[1][0] = -axisY.x;
m[1][1] = -axisY.y;
m[1][2] = -axisY.z;
m[2][0] = axisZ.x;
m[2][1] = axisZ.y;
m[2][2] = axisZ.z;
Coordinates p = new Coordinates(x, y, z).rotate(m).add(c3);
int hydrogen = mMol.addAtom(atomicNo);
mMol.addBond(rootAtom, hydrogen, Molecule.cBondTypeSingle);
mMol.setAtomX(hydrogen, p.x);
mMol.setAtomY(hydrogen, p.y);
mMol.setAtomZ(hydrogen, p.z);
}
}