Search in sources :

Example 1 with GroupContainer

use of de.bioforscher.jstructure.model.structure.container.GroupContainer 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 GroupContainer

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

the class SelectionTest method shouldNameContainer.

@Test
public void shouldNameContainer() {
    GroupContainer container = protein.select().aminoAcids().nameContainer(givenName).asGroupContainer();
    Assert.assertTrue(container.getIdentifier().equals(givenName));
}
Also used : GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer) Test(org.junit.Test)

Example 3 with GroupContainer

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

the class ModelIntegrityTest method shouldGetGroupCopy.

@Test
public void shouldGetGroupCopy() {
    GroupContainer copiedGroups = protein.select().chainName("A", "C").groupName(Asparagine.THREE_LETTER_CODE).asGroupContainer().createCopy();
    Assert.assertTrue(copiedGroups instanceof Chain);
    System.out.println(copiedGroups.getPdbRepresentation());
}
Also used : Chain(de.bioforscher.jstructure.model.structure.Chain) GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer) Test(org.junit.Test)

Example 4 with GroupContainer

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

the class CopyableTest method shouldCloneConcreteImplementationsOfAminoAcids.

@Test
public void shouldCloneConcreteImplementationsOfAminoAcids() {
    // clone containers led to groups losing their identity meaning they were no longer concrete amino acid
    // implementations but mere groups
    // will fail when copy does not contain amino acids
    ChainContainer proteinCopy = protein.createDeepCopy();
    System.out.println(proteinCopy.getAminoAcidSequence());
    Assert.assertFalse("no amino acid sequence - clone compromised", proteinCopy.getAminoAcidSequence().isEmpty());
    GroupContainer chainCopy = protein.getChains().get(0).createDeepCopy();
    System.out.println(chainCopy.getAminoAcidSequence());
    Assert.assertFalse("no amino acid sequence - clone compromised", chainCopy.getAminoAcidSequence().isEmpty());
}
Also used : ChainContainer(de.bioforscher.jstructure.model.structure.container.ChainContainer) GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer) Test(org.junit.Test)

Example 5 with GroupContainer

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

the class StructureCollectorsTest method shouldKeepStructureReferenceGroup.

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

Aggregations

GroupContainer (de.bioforscher.jstructure.model.structure.container.GroupContainer)9 Test (org.junit.Test)7 Transformation (de.bioforscher.jstructure.mathematics.Transformation)1 Pair (de.bioforscher.jstructure.model.Pair)1 Chain (de.bioforscher.jstructure.model.structure.Chain)1 Group (de.bioforscher.jstructure.model.structure.Group)1 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)1 AtomContainer (de.bioforscher.jstructure.model.structure.container.AtomContainer)1 ChainContainer (de.bioforscher.jstructure.model.structure.container.ChainContainer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)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