Java Code Examples for org.biojava.nbio.structure.align.model.AFPChain#setBlockRotationMatrix()

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#setBlockRotationMatrix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlignmentTools.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Fundamentally, an alignment is just a list of aligned residues in each
 * protein. This method converts two lists of ResidueNumbers into an
 * AFPChain.
 *
 * <p>Parameters are filled with defaults (often null) or sometimes
 * calculated.
 *
 * <p>For a way to modify the alignment of an existing AFPChain, see
 * {@link AlignmentTools#replaceOptAln(AFPChain, Atom[], Atom[], Map)}
 * @param ca1 CA atoms of the first protein
 * @param ca2 CA atoms of the second protein
 * @param aligned1 A list of aligned residues from the first protein
 * @param aligned2 A list of aligned residues from the second protein.
 *  Must be the same length as aligned1.
 * @return An AFPChain representing the alignment. Many properties may be
 *  null or another default.
 * @throws StructureException if an error occured during superposition
 * @throws IllegalArgumentException if aligned1 and aligned2 have different
 *  lengths
 * @see AlignmentTools#replaceOptAln(AFPChain, Atom[], Atom[], Map)
 */
public static AFPChain createAFPChain(Atom[] ca1, Atom[] ca2,
									  ResidueNumber[] aligned1, ResidueNumber[] aligned2 ) throws StructureException {
	//input validation
	int alnLen = aligned1.length;
	if(alnLen != aligned2.length) {
		throw new IllegalArgumentException("Alignment lengths are not equal");
	}

	AFPChain a = new AFPChain(AFPChain.UNKNOWN_ALGORITHM);
	try {
		a.setName1(ca1[0].getGroup().getChain().getStructure().getName());
		if(ca2[0].getGroup().getChain().getStructure() != null) {
			// common case for cloned ca2
			a.setName2(ca2[0].getGroup().getChain().getStructure().getName());
		}
	} catch(Exception e) {
		// One of the structures wasn't fully created. Ignore
	}
	a.setBlockNum(1);
	a.setCa1Length(ca1.length);
	a.setCa2Length(ca2.length);

	a.setOptLength(alnLen);
	a.setOptLen(new int[] {alnLen});


	Matrix[] ms = new Matrix[a.getBlockNum()];
	a.setBlockRotationMatrix(ms);
	Atom[] blockShiftVector = new Atom[a.getBlockNum()];
	a.setBlockShiftVector(blockShiftVector);

	String[][][] pdbAln = new String[1][2][alnLen];
	for(int i=0;i<alnLen;i++) {
		pdbAln[0][0][i] = aligned1[i].getChainName()+":"+aligned1[i];
		pdbAln[0][1][i] = aligned2[i].getChainName()+":"+aligned2[i];
	}

	a.setPdbAln(pdbAln);

	// convert pdbAln to optAln, and fill in some other basic parameters
	AFPChainXMLParser.rebuildAFPChain(a, ca1, ca2);

	return a;

	// Currently a single block. Split into several blocks by sequence if needed
	//		return AlignmentTools.splitBlocksByTopology(a,ca1,ca2);
}
 
Example 2
Source File: AlignmentTools.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** Rotate the Atoms/Groups so they are aligned for the 3D visualisation
 *
 * @param afpChain
 * @param ca1
 * @param ca2
 * @return an array of Groups that are transformed for 3D display
 * @throws StructureException
 */
public static Group[] prepareGroupsForDisplay(AFPChain afpChain, Atom[] ca1, Atom[] ca2) throws StructureException{


	if ( afpChain.getBlockRotationMatrix().length == 0 ) {
		// probably the alignment is too short!
		System.err.println("No rotation matrix found to rotate 2nd structure!");
		afpChain.setBlockRotationMatrix(new Matrix[]{Matrix.identity(3, 3)});
		afpChain.setBlockShiftVector(new Atom[]{new AtomImpl()});
	}

	// List of groups to be rotated according to the alignment
	Group[] twistedGroups = new Group[ ca2.length];

	//int blockNum = afpChain.getBlockNum();

	int i = -1;

	// List of groups from the structure not included in ca2 (e.g. ligands)
	// Will be rotated according to first block
	List<Group> hetatms2 = StructureTools.getUnalignedGroups(ca2);

	if (  (afpChain.getAlgorithmName().equals(FatCatRigid.algorithmName) ) || (afpChain.getAlgorithmName().equals(FatCatFlexible.algorithmName) ) ){

		for (Atom a: ca2){
			i++;
			twistedGroups[i]=a.getGroup();

		}

		twistedGroups = AFPTwister.twistOptimized(afpChain, ca1, ca2);

		//} else  if  (( blockNum == 1 ) || (afpChain.getAlgorithmName().equals(CeCPMain.algorithmName))) {
	} else {

		Matrix m   =  afpChain.getBlockRotationMatrix()[ 0];
		Atom shift =  afpChain.getBlockShiftVector()   [ 0 ];

		shiftCA2(afpChain, ca2, m,shift, twistedGroups);

	}

	if ( afpChain.getBlockNum() > 0){

		// Superimpose ligands relative to the first block
		if( hetatms2.size() > 0 ) {

			if ( afpChain.getBlockRotationMatrix().length > 0 ) {

				Matrix m1      = afpChain.getBlockRotationMatrix()[0];
				//m1.print(3,3);
				Atom   vector1 = afpChain.getBlockShiftVector()[0];
				//System.out.println("shift vector:" + vector1);

				for ( Group g : hetatms2){
					Calc.rotate(g, m1);
					Calc.shift(g,vector1);
				}
			}
		}
	}

	return twistedGroups;
}
 
Example 3
Source File: AFPTwister.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * transform the coordinates in the ca2 according to the superimposing of
 * the given position pairs. No Cloning, transforms input atoms.
 */
// orig name: transPdb
private static void transformOrigPDB(int n, int[] res1, int[] res2,
		Atom[] ca1, Atom[] ca2, AFPChain afpChain, int blockNr)
		throws StructureException {
	logger.debug(
			"transforming original coordinates {} len1: {} res1: {} len2: {} res2: {}",
			n, ca1.length, res1.length, ca2.length, res2.length);

	Atom[] cod1 = getAtoms(ca1, res1, n, false);
	Atom[] cod2 = getAtoms(ca2, res2, n, false);

	// double *cod1 = pro1->Cod4Res(n, res1);
	// double *cod2 = pro2->Cod4Res(n, res2);

	Matrix4d transform = SuperPositions.superpose(Calc.atomsToPoints(cod1),
			Calc.atomsToPoints(cod2));

	Matrix r = Matrices.getRotationJAMA(transform);
	Atom t = Calc.getTranslationVector(transform);

	logger.debug("transPdb: transforming orig coordinates with matrix: {}",
			r);

	if (afpChain != null) {
		Matrix[] ms = afpChain.getBlockRotationMatrix();
		if (ms == null)
			ms = new Matrix[afpChain.getBlockNum()];

		ms[blockNr] = r;

		Atom[] shifts = afpChain.getBlockShiftVector();
		if (shifts == null)
			shifts = new Atom[afpChain.getBlockNum()];
		shifts[blockNr] = t;

		afpChain.setBlockRotationMatrix(ms);
		afpChain.setBlockShiftVector(shifts);
	}

	for (Atom a : ca2)
		Calc.transform(a.getGroup(), transform);

}
 
Example 4
Source File: TestAFPChainConversion.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testAFPconversion() throws Exception{

	//Fill an AFPChain with the general information
	AFPChain afp = new AFPChain("algorithm");
	afp.setName1("name1");
	afp.setName2("name2");
	afp.setVersion("1.0");
	afp.setCalculationTime(System.currentTimeMillis());
	//Generate a optimal alignment with 3 blocks and 5 residues per block
	int[][][] optAln = new int[3][][];
	for (int b=0; b<optAln.length; b++){
		int[][] block = new int[2][];
		for (int c=0; c<block.length; c++){
			int[] residues = {b+5,b+6,b+7,b+8,b+9};
			block[c] = residues;
		}
		optAln[b] = block;
	}
	afp.setOptAln(optAln);
	afp.setBlockNum(optAln.length);
	//Set the rotation matrix and shift to random numbers
	double[][] mat = {{0.13,1.5,0.84},{1.3,0.44,2.3},{1.0,1.2,2.03}};
	Matrix rot = new Matrix(mat);
	Atom shift = new AtomImpl();
	shift.setX(0.44);
	shift.setY(0.21);
	shift.setZ(0.89);
	Matrix[] blockRot = {rot,rot,rot};
	afp.setBlockRotationMatrix(blockRot);
	Atom[] blockShift = {shift,shift,shift};
	afp.setBlockShiftVector(blockShift);

	//Convert the AFPChain into a MultipleAlignment (without Atoms)
	MultipleAlignmentEnsemble ensemble =
			new MultipleAlignmentEnsembleImpl(afp,null,null,true);
	MultipleAlignment msa = ensemble.getMultipleAlignment(0);

	//Test for all the information
	assertEquals(afp.getName1(),ensemble.getStructureIdentifiers().get(0).getIdentifier());
	assertEquals(afp.getName2(), ensemble.getStructureIdentifiers().get(1).getIdentifier());
	assertEquals(afp.getAlgorithmName(), ensemble.getAlgorithmName());
	assertEquals(afp.getVersion(),ensemble.getVersion());
	assertTrue(ensemble.getCalculationTime().equals(
			afp.getCalculationTime()));
	assertEquals(afp.getBlockNum(), msa.getBlockSets().size());
	for (int b = 0; b<afp.getBlockNum(); b++){
		assertEquals(Calc.getTransformation(
				afp.getBlockRotationMatrix()[b],
				afp.getBlockShiftVector()[b]),
				msa.getBlockSet(b).getTransformations().get(1));
	}

	//Test for the scores
	assertEquals(msa.getScore(MultipleAlignmentScorer.CE_SCORE),
			(Double) afp.getAlignScore());
	assertEquals(msa.getScore(MultipleAlignmentScorer.AVGTM_SCORE),
			(Double) afp.getTMScore());
	assertEquals(msa.getScore(MultipleAlignmentScorer.RMSD),
			(Double) afp.getTotalRmsdOpt());


	//Test for the optimal alignment
	for (int b=0; b<3; b++){
		for (int c=0; c<2; c++){
			for (int res=0; res<5; res++){
				Integer afpRes = afp.getOptAln()[b][c][res];
				assertEquals(afpRes, msa.getBlock(b).
						getAlignRes().get(c).get(res));
			}
		}
	}
}