com.actelion.research.chem.shredder.FragmentGeometry3D 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
package com.actelion.research.chem.shredder;
import com.actelion.research.calc.Matrix;
import com.actelion.research.calc.SingularValueDecomposition;
import com.actelion.research.chem.Coordinates;
import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.StereoMolecule;
import java.util.ArrayList;
import java.util.Arrays;
public class FragmentGeometry3D {
public static final int MODE_SELECTED_ATOMS = 1; // molecule with fragment atoms selected, exit vector atoms not selected
public static final int MODE_FRAGMENT_WITH_EXIT_VECTORS = 2; // defined as atom custom label "*"
private StereoMolecule mMol;
private ExitVector[] mExitVector;
private String mFootPrint; // canonical String describing atomic numbers or exit vectors
private int[][] mPermutation;
private Coordinates[] mAlignmentCoords;
private Coordinates mAlignmentCOG;
/**
* Creates a FragmentGeometry3D from a StereoMolecule with the mode defining the situation.
* This creates a canonical exit vector footprint. For geometries with the same footprint
* it provides geometry comparisons regarding alignment and exit vector similarity.
* A transformation mask is provided for the best alignment one object to another.
* Helper functions to attach properly aligned substituents are given.
* @param mol
*/
public FragmentGeometry3D(StereoMolecule mol, int mode) {
mMol = mol;
mMol.ensureHelperArrays(Molecule.cHelperNeighbours);
switch (mode) {
case MODE_SELECTED_ATOMS:
initMoleculeWithSelection();
break;
case MODE_FRAGMENT_WITH_EXIT_VECTORS:
initFragmentWithExitVectors();
break;
}
Arrays.sort(mExitVector);
StringBuilder footprint = new StringBuilder();
for (ExitVector ev : mExitVector)
footprint.append(Molecule.cAtomLabel[ev.atomicNo]);
mFootPrint = footprint.toString();
// compile coordinates of all root atoms and calculat their center of gravity
mAlignmentCoords = new Coordinates[2*mExitVector.length];
for (int i=0; i exitVectorList = new ArrayList<>();
for (int atom=0; atom exitVectorList = new ArrayList<>();
for (int atom=0; atom maxRMSD ? null : matrix;
}
public boolean hasMatchingExitVectors(FragmentGeometry3D geometry, Coordinates[] coords, int permutation, double maxDiversion) {
for (int i = 0; i maxDiversion)
return false;
}
return true;
}
public int getPermutationCount() {
if (mPermutation == null) {
int[] sameCount = new int[mExitVector.length];
int[] permCount = new int[mExitVector.length];
int index = 0;
int totalPermCount = 1;
while (index list = new ArrayList<>();
addToPermutation(new int[1], objectCount, list);
return list.toArray(new int[0][]);
}
private void addToPermutation(int[] input, int max, ArrayList list) {
int size = input.length + 1;
for (int pos=0; pos
* To actually perform the alignment with any set of coordinates do:
* for (Coordinates c : anyCoords) { c.sub(cog2); c.rotate(matrix); c.add(cog1); }
* @param coords1
* @param coords2
* @param cog1
* @param cog2
* @return
*/
public static double[][] kabschAlign(Coordinates[] coords1, Coordinates[] coords2,
Coordinates cog1, Coordinates cog2) {
double[][] m = new double[3][3];
double[][] c1 = Arrays.stream(coords1).map(e -> new double[] {e.x-cog1.x,e.y-cog1.y,e.z-cog1.z}).toArray(double[][]::new);
double[][] c2 = Arrays.stream(coords2).map(e -> new double[] {e.x-cog2.x,e.y-cog2.y,e.z-cog2.z}).toArray(double[][]::new);
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
double rij = 0.0;
for(int a=0; a0.0);
rot = rot.getTranspose();
return rot.getArray();
}
private static class ExitVector implements Comparable {
int rootAtom,exitAtom,atomicNo;
public ExitVector(int rootAtom, int exitAtom, int atomicNo) {
this.rootAtom = rootAtom;
this.exitAtom = exitAtom;
this.atomicNo = atomicNo;
}
@Override
public int compareTo(ExitVector o) {
return Integer.compare(o.atomicNo, atomicNo);
}
}
}