@@ -41,7 +41,7 @@ public class MultipleAlignmentScorer {
4141 public static void calculateScores (MultipleAlignment alignment ) throws StructureException {
4242
4343 //Put RMSD
44- List <Atom []> transformed = transformAtoms (alignment );
44+ List <Atom []> transformed = MultipleAlignmentTools . transformAtoms (alignment );
4545 alignment .putScore (RMSD , getRMSD (transformed ));
4646
4747 //Put TM-Score
@@ -52,82 +52,6 @@ public static void calculateScores(MultipleAlignment alignment) throws Structure
5252 alignment .putScore (AVG_TMSCORE , getAvgTMScore (transformed ,lengths ));
5353 }
5454
55- /**
56- * Transforms atoms according to the superposition stored in the alignment.
57- * <p>
58- * For each structure in the alignment, returns an atom for each
59- * representative atom in the aligned columns, omitting unaligned residues
60- * (i.e. an array of length <tt>alignment.length()</tt> ).
61- * <p>
62- * All blocks are concatenated together, so Atoms may not appear in the
63- * same order as in their parent structure. If the alignment blocks contain
64- * null residues (gaps), then the returned array will also contain null Atoms.
65- *
66- * @param alignment MultipleAlignment
67- * @return
68- */
69- public static List <Atom []> transformAtoms (MultipleAlignment alignment ) {
70- if (alignment .getEnsemble () == null ) {
71- throw new NullPointerException ("No ensemble set for this alignment" );
72- }
73-
74- List <Atom []> atomArrays = alignment .getEnsemble ().getAtomArrays ();
75- List <Atom []> transformed = new ArrayList <Atom []>(atomArrays .size ());
76-
77- //Loop through structures
78- for (int i =0 ; i <atomArrays .size (); i ++){
79-
80- Matrix4d transform = null ;
81- if ( alignment .getTransformations () != null ) {
82- transform = alignment .getTransformations ().get (i );
83- }
84- Atom [] curr = atomArrays .get (i ); // all CA atoms from structure
85-
86- //Concatenated list of all blocks for this structure
87- Atom [] transformedAtoms = new Atom [alignment .length ()];
88- int transformedAtomsLength = 0 ;
89-
90- // Each blockset gets transformed independently
91- for ( BlockSet bs : alignment .getBlockSets ()) {
92-
93- Atom [] blocksetAtoms = new Atom [bs .length ()];
94-
95- for ( Block blk : bs .getBlocks () ) {
96- if ( blk .size () != atomArrays .size ()) {
97- throw new IllegalStateException (String .format (
98- "Mismatched block length. Expected %d structures, found %d." ,
99- atomArrays .size (),blk .size () ));
100- }
101- //Extract aligned atoms
102- for (int j =0 ; j <blk .length (); j ++){
103- Integer alignedPos = blk .getAlignRes ().get (i ).get (j );
104- if (alignedPos != null ) {
105- blocksetAtoms [j ] = (Atom ) curr [alignedPos ].clone ();
106- }
107- }
108- }
109-
110- // transform according to (1) the blockset matrix, or (2) the alignment matrix
111- Matrix4d blockTrans = null ;
112- if (bs .getTransformations () != null )
113- blockTrans = bs .getTransformations ().get (i );
114- if (blockTrans == null ) {
115- blockTrans = transform ;
116- }
117-
118- for (Atom a : blocksetAtoms ) {
119- if (a !=null ) Calc .transform (a , blockTrans );
120- transformedAtoms [transformedAtomsLength ] = a ;
121- transformedAtomsLength ++;
122- }
123- }
124- assert (transformedAtomsLength == alignment .length ());
125-
126- transformed .add (transformedAtoms );
127- }
128- return transformed ;
129- }
130-
13155 /**
13256 * Calculates the RMSD of all-to-all structure comparisons (distances) of the
13357 * given MultipleAlignment. <p>
@@ -142,7 +66,7 @@ public static List<Atom[]> transformAtoms(MultipleAlignment alignment) {
14266 * @return double RMSD
14367 */
14468 public static double getRMSD (MultipleAlignment alignment ) {
145- List <Atom []> transformed = transformAtoms (alignment );
69+ List <Atom []> transformed = MultipleAlignmentTools . transformAtoms (alignment );
14670 return getRMSD (transformed );
14771 }
14872 /**
@@ -183,7 +107,7 @@ private static double getRMSD(List<Atom[]> transformed) {
183107 }
184108
185109 public static double getRefRMSD (MultipleAlignment alignment , int reference ) {
186- List <Atom []> transformed = transformAtoms (alignment );
110+ List <Atom []> transformed = MultipleAlignmentTools . transformAtoms (alignment );
187111 return getRefRMSD (transformed ,reference );
188112 }
189113 /**
@@ -244,7 +168,7 @@ private static double getRefRMSD(List<Atom[]> transformed, int reference) {
244168 * @throws StructureException
245169 */
246170 public static double getAvgTMScore (MultipleAlignment alignment ) throws StructureException {
247- List <Atom []> transformed = transformAtoms (alignment );
171+ List <Atom []> transformed = MultipleAlignmentTools . transformAtoms (alignment );
248172 List <Integer > lengths = new ArrayList <Integer >(alignment .size ());
249173 for (Atom [] atoms : alignment .getEnsemble ().getAtomArrays ()) {
250174 lengths .add (atoms .length );
@@ -304,7 +228,7 @@ private static double getAvgTMScore(List<Atom[]> transformed, List<Integer> leng
304228 * @throws StructureException
305229 */
306230 public static double getRefTMScore (MultipleAlignment alignment , int reference ) throws StructureException {
307- List <Atom []> transformed = transformAtoms (alignment );
231+ List <Atom []> transformed = MultipleAlignmentTools . transformAtoms (alignment );
308232 List <Integer > lengths = new ArrayList <Integer >(alignment .size ());
309233 for (Atom [] atoms : alignment .getEnsemble ().getAtomArrays ()) {
310234 lengths .add (atoms .length );
@@ -366,7 +290,7 @@ private static double getRefTMScore(List<Atom[]> transformed, List<Integer> leng
366290 */
367291 public static double getCEMCScore (MultipleAlignment alignment ) throws StructureException {
368292 //Transform Atoms
369- List <Atom []> transformed = transformAtoms (alignment );
293+ List <Atom []> transformed = MultipleAlignmentTools . transformAtoms (alignment );
370294 //Calculate d0
371295 int minLen = Integer .MAX_VALUE ;
372296 for (Atom [] atoms : alignment .getEnsemble ().getAtomArrays ())
@@ -375,6 +299,17 @@ public static double getCEMCScore(MultipleAlignment alignment) throws StructureE
375299 return getCEMCScore (transformed , d0 );
376300 }
377301
302+ /**
303+ * Calculates the CEMC score, specific for the MultipleAlignment algorithm.
304+ * The score function is modified from the original CEMC paper, making it
305+ * continuous and differentiable.<p>
306+ * Complexity: T(n,l) = O(l*n^2), if n=number of structures and l=alignment length.
307+ *
308+ * @param transformed List of transformed Atom arrays
309+ * @param d0 parameter for the distance evaluation
310+ * @return
311+ * @throws StructureException
312+ */
378313 private static double getCEMCScore (List <Atom []> transformed , double d0 ) throws StructureException {
379314
380315 int size = transformed .size ();
0 commit comments