Search in sources :

Example 1 with AtomContainer

use of de.bioforscher.jstructure.model.structure.container.AtomContainer in project jstructure by JonStargaryen.

the class SVDSuperimposer method align.

@Override
public StructureAlignmentResult align(AtomContainer reference, AtomContainer query) {
    AtomContainer originalReference = reference;
    AtomContainer originalCandidate = query;
    Pair<GroupContainer, GroupContainer> atomContainerPair = AbstractAlignmentAlgorithm.comparableGroupContainerPair(reference, query, minimalSetOfAtomNames, maximalSetOfAtomNames);
    reference = atomContainerPair.getLeft();
    query = atomContainerPair.getRight();
    // calculate centroids
    double[] centroid1 = reference.calculate().centroid().getValue();
    double[] centroid2 = query.calculate().centroid().getValue();
    // center atoms
    reference.calculate().center();
    query.calculate().center();
    // compose covariance matrix and calculate SVD
    RealMatrix matrix1 = convertToMatrix(reference);
    RealMatrix matrix2 = convertToMatrix(query);
    RealMatrix covariance = matrix2.transpose().multiply(matrix1);
    SingularValueDecomposition svd = new SingularValueDecomposition(covariance);
    // R = (V * U')'
    RealMatrix ut = svd.getU().transpose();
    RealMatrix rotationMatrix = svd.getV().multiply(ut).transpose();
    // check if reflection
    if (new LUDecomposition(rotationMatrix).getDeterminant() < 0) {
        RealMatrix v = svd.getV().transpose();
        v.setEntry(2, 0, (0 - v.getEntry(2, 0)));
        v.setEntry(2, 1, (0 - v.getEntry(2, 1)));
        v.setEntry(2, 2, (0 - v.getEntry(2, 2)));
        rotationMatrix = v.transpose().multiply(ut).transpose();
    }
    double[][] rotation = rotationMatrix.getData();
    // calculate translation
    double[] translation = LinearAlgebra.on(centroid1).subtract(LinearAlgebra.on(centroid2).multiply(rotation)).getValue();
    logger.trace("rotation matrix\n{}\ntranslation vector\n{}", Arrays.deepToString(rotationMatrix.getData()), Arrays.toString(translation));
    /* transform 2nd atom select - employ neutral translation (3D vector of zeros), because the atoms are already
        * centered and calculate RMSD */
    query.calculate().transform(new Transformation(rotation));
    double rmsd = calculateRmsd(reference, query);
    // return alignment
    return new StructureAlignmentResult(originalReference, originalCandidate, query, rmsd, translation, rotation);
}
Also used : Transformation(de.bioforscher.jstructure.mathematics.Transformation) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) AtomContainer(de.bioforscher.jstructure.model.structure.container.AtomContainer) LUDecomposition(org.apache.commons.math3.linear.LUDecomposition) SingularValueDecomposition(org.apache.commons.math3.linear.SingularValueDecomposition) GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer)

Example 2 with AtomContainer

use of de.bioforscher.jstructure.model.structure.container.AtomContainer in project jstructure by JonStargaryen.

the class StructureCollectorsTest method toAtomContainer.

@Test
public void toAtomContainer() throws Exception {
    //TODO rework concept, has there to be some structure for atoms (i.e. organize selection again into chains e.g.)
    AtomContainer container = protein.atoms().collect(StructureCollectors.toAtomContainer());
    container.atoms().forEach(atom -> {
        Assert.assertEquals("parent reference was lost", "1brr", atom.getParentGroup().getParentChain().getParentProtein().getPdbId().getPdbId());
    });
}
Also used : AtomContainer(de.bioforscher.jstructure.model.structure.container.AtomContainer) Test(org.junit.Test)

Example 3 with AtomContainer

use of de.bioforscher.jstructure.model.structure.container.AtomContainer in project jstructure by JonStargaryen.

the class ModelIntegrityTest method shouldGetAtomCopy.

@Test
public void shouldGetAtomCopy() {
    AtomContainer clonedSelectedAtoms = protein.select().chainName("A", "B").aminoAcids().groupName(Histidine.THREE_LETTER_CODE).atomName(AminoAcid.ALPHA_CARBON_NAME).asAtomContainer().createCopy();
    System.out.println(clonedSelectedAtoms.getPdbRepresentation());
}
Also used : AtomContainer(de.bioforscher.jstructure.model.structure.container.AtomContainer) Test(org.junit.Test)

Example 4 with AtomContainer

use of de.bioforscher.jstructure.model.structure.container.AtomContainer in project jstructure by JonStargaryen.

the class StructureCollectorsTest method shouldKeepStructureReferenceAtom.

@Test
public void shouldKeepStructureReferenceAtom() throws Exception {
    AtomContainer container = protein.atoms().collect(StructureCollectors.toIsolatedStructure());
    container.atoms().forEach(atom -> Assert.assertEquals("parent reference was lost", "1brr", atom.getParentGroup().getParentChain().getParentStructure().getProteinIdentifier().getPdbId()));
}
Also used : AtomContainer(de.bioforscher.jstructure.model.structure.container.AtomContainer) Test(org.junit.Test)

Example 5 with AtomContainer

use of de.bioforscher.jstructure.model.structure.container.AtomContainer in project jstructure by JonStargaryen.

the class StructureCollectorsTest method shouldNotManipulateStaticUnknownInstance.

@Test
public void shouldNotManipulateStaticUnknownInstance() {
    // protein/chain/group contain 'unknown' instances which are the home to clone model instances without parent reference
    Group unknownGroup = Group.UNKNOWN_GROUP;
    Assert.assertTrue(unknownGroup.getAtoms().isEmpty());
    // collecting stuff to an AtomContainer will clone the unknown instance and assign the cloned atoms to that container
    AtomContainer atomContainer = protein.atoms().collect(StructureCollectors.toIsolatedStructure());
    // references should be distinct
    Assert.assertNotEquals(unknownGroup, atomContainer);
    // original unknown group should still not contain any children
    Assert.assertTrue(unknownGroup.getAtoms().isEmpty());
}
Also used : AtomContainer(de.bioforscher.jstructure.model.structure.container.AtomContainer) Test(org.junit.Test)

Aggregations

AtomContainer (de.bioforscher.jstructure.model.structure.container.AtomContainer)7 Test (org.junit.Test)6 Transformation (de.bioforscher.jstructure.mathematics.Transformation)1 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)1 GroupContainer (de.bioforscher.jstructure.model.structure.container.GroupContainer)1 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)1 LUDecomposition (org.apache.commons.math3.linear.LUDecomposition)1 RealMatrix (org.apache.commons.math3.linear.RealMatrix)1 SingularValueDecomposition (org.apache.commons.math3.linear.SingularValueDecomposition)1