|
| 1 | +package org.biojava.nbio.structure.symmetry.gui; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.biojava.nbio.structure.Atom; |
| 7 | +import org.biojava.nbio.structure.Structure; |
| 8 | +import org.biojava.nbio.structure.StructureException; |
| 9 | +import org.biojava.nbio.structure.StructureTools; |
| 10 | +import org.biojava.nbio.structure.align.gui.AlignmentCalculationRunnable; |
| 11 | +import org.biojava.nbio.structure.align.gui.jmol.MultipleAlignmentJmol; |
| 12 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignment; |
| 13 | +import org.biojava.nbio.structure.symmetry.internal.CESymmParameters; |
| 14 | +import org.biojava.nbio.structure.symmetry.internal.CeSymm; |
| 15 | +import org.slf4j.Logger; |
| 16 | +import org.slf4j.LoggerFactory; |
| 17 | + |
| 18 | +/** |
| 19 | + * Calculates a symmetry analysis and displays the results. |
| 20 | + * Linked to the SymmetryGUI. |
| 21 | + * Does not generalize, uses CeSymm class directly to allow |
| 22 | + * for the symmetry axis recovery. |
| 23 | + * |
| 24 | + * @author Aleix Lafita |
| 25 | + * |
| 26 | + */ |
| 27 | +public class SymmetryCalc implements AlignmentCalculationRunnable { |
| 28 | + |
| 29 | + private static final Logger logger = |
| 30 | + LoggerFactory.getLogger(SymmetryCalc.class); |
| 31 | + |
| 32 | + boolean interrupted = false; |
| 33 | + |
| 34 | + private String name; |
| 35 | + private Structure structure; |
| 36 | + private SymmetryGui parent; |
| 37 | + |
| 38 | + /** Requests for a structure to analyze. |
| 39 | + */ |
| 40 | + public SymmetryCalc(SymmetryGui p, Structure s, String n) { |
| 41 | + parent = p; |
| 42 | + structure = s; |
| 43 | + name = n; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void run() { |
| 48 | + |
| 49 | + //The structure has been downloaded, now calculate the alignment ... |
| 50 | + CeSymm algorithm = parent.getSymmetryAlgorithm(); |
| 51 | + CESymmParameters params = (CESymmParameters) algorithm.getParameters(); |
| 52 | + |
| 53 | + try { |
| 54 | + |
| 55 | + List<Atom[]> atoms = new ArrayList<Atom[]>(); |
| 56 | + atoms.add(StructureTools.getRepresentativeAtomArray(structure)); |
| 57 | + |
| 58 | + MultipleAlignment msa = algorithm.align(atoms); |
| 59 | + |
| 60 | + List<String> names = new ArrayList<String>(); |
| 61 | + for (int su=0; su<msa.size(); su++){ |
| 62 | + names.add(name); |
| 63 | + } |
| 64 | + msa.getEnsemble().setStructureNames(names); |
| 65 | + |
| 66 | + MultipleAlignmentJmol jmol = |
| 67 | + SymmetryDisplay.display(msa, algorithm.getSymmetryAxes()); |
| 68 | + String title = jmol.getTitle(); |
| 69 | + |
| 70 | + if (params != null) |
| 71 | + title += " | OrderDetector=" + params.getOrderDetectorMethod()+ |
| 72 | + " Refiner: "+params.getRefineMethod(); |
| 73 | + jmol.setTitle(title); |
| 74 | + |
| 75 | + } catch (StructureException e){ |
| 76 | + logger.warn(e.getMessage()); |
| 77 | + } |
| 78 | + parent.notifyCalcFinished(); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public void interrupt() { |
| 83 | + interrupted = true; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void cleanup() { |
| 88 | + |
| 89 | + parent.notifyCalcFinished(); |
| 90 | + parent = null; |
| 91 | + structure = null; |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public void setNrCPUs(int useNrCPUs) {} |
| 96 | +} |
0 commit comments