Given a symmetry result, it calculates the overall global symmetry,
factoring out the alignment and detection steps of
{@link QuatSymmetryDetector} algorithm.

@param result
symmetry result
@return global symmetry results
@throws StructureException
186352
public static QuatSymmetryResults getQuaternarySymmetry(CeSymmResult result)
			throws StructureException {

		// Obtain the subunits of the repeats
		List<Atom[]> atoms = toRepeatsAlignment(result).getAtomArrays();
		List<Subunit> subunits = atoms.stream()
				.map(a -> new Subunit(a, null, null, null))
				.collect(Collectors.toList());

		// The clustering thresholds are set to 0 so that all always merged
		SubunitClustererParameters cp = new SubunitClustererParameters();
		cp.setClustererMethod(SubunitClustererMethod.STRUCTURE);
		cp.setRMSDThreshold(10.0);
		cp.setStructureCoverageThreshold(0.0);

		QuatSymmetryParameters sp = new QuatSymmetryParameters();

		QuatSymmetryResults gSymmetry = QuatSymmetryDetector
				.calcGlobalSymmetry(subunits, sp, cp);

		return gSymmetry;
	}
118217
public static <T> Future<T> ofResult(final T result) {
        return Future.of(CompletableFuture.completedFuture(result));
    }
825051
public void align(Structure s1, Structure s2, StrucAligParameters params)
			throws StructureException {
		// step 1 convert the structures to Atom Arrays

		Atom[] ca1 = getAlignmentAtoms(s1);
		Atom[] ca2 = getAlignmentAtoms(s2);

		notifyStartingAlignment(s1.getName(), ca1, s2.getName(), ca2);
		align(ca1, ca2, params);
	}
1113310
@SuppressWarnings("unchecked")
  T result(final Object r) {
    return (T) (r == NULL ? null : r);
  }
574731
public ExecutionResult toExecutionResult() {
        ExecutionResult executionResult = new ExecutionResultImpl(this);
        if (!this.getUnderlyingErrors().isEmpty()) {
            executionResult = new ExecutionResultImpl(this.getUnderlyingErrors());
        }
        return executionResult;
    }
846120
public static void ensureClusteringResult(final Database db, final Result result) {
    Collection<Clustering<?>> clusterings = ResultUtil.filterResults(db.getHierarchy(), result, Clustering.class);
    if(clusterings.isEmpty()) {
      ResultUtil.addChildResult(db, new ByLabelOrAllInOneClustering().run(db));
    }
  }
265905
public GeoServiceGeocodingResult toGeoServiceGeocodingResult(
            final GeocodingResult result) {
        if (result == null) {
            return null;
        }
        return new GeoServiceGeocodingResult(
                result.addressComponents,
                result.formattedAddress,
                result.postcodeLocalities,
                toGeoServiceGeometry(result.geometry),
                result.types,
                result.partialMatch,
                result.placeId);
    }
891092
public static ResultDescriptor ofResult(final Class<? extends AnalyzerResult> resultClass) {
        ResultDescriptor resultDescriptor = _resultDescriptors.get(resultClass);
        if (resultDescriptor == null) {
            resultDescriptor = new ResultDescriptorImpl(resultClass);
            _resultDescriptors.put(resultClass, resultDescriptor);
        }
        return resultDescriptor;
    }
605349
public ComplexFloat addi(ComplexFloat c, ComplexFloat result) {
    if (this == result) {
      r += c.r;
      i += c.i;
    } else {
      result.r = r + c.r;
      result.i = i + c.i;
    }
    return result;
  }
417270
public void mul(double b, IVector result) {
        if (result.size != size) result.reshape(size);

        int i;
        for (i = 0; i < size; i++) {
            result.realvector[i] = realvector[i] * b;
            result.imagvector[i] = imagvector[i] * b;
        }
    }
402326
public void process() throws IOException, StructureException {
		if(sequences == null) { // only process once, then return cached values
			LinkedHashMap<String, ProteinSequence> sequenceMap = reader.process();

			sequences = sequenceMap.values().toArray(new ProteinSequence[0]);
			accessions = new String[sequences.length];
			structures = new Structure[sequences.length];
			residues = new ResidueNumber[sequences.length][];

			// Match each sequence  to a series of PDB Residue numbers
			for(int i=0;i<sequences.length;i++) {
				accessions[i] = sequences[i].getAccession().getID();

				//System.out.println("Fetching "+accession);
				structures[i] = cache.getStructure(accessions[i]);

				residues[i] = StructureSequenceMatcher.matchSequenceToStructure(sequences[i], structures[i]);

				assert( residues[i].length == sequences[i].getLength());
			}
		}
	}
142830
public void align(Structure s1, String chainId1, Structure s2,
			String chainId2, StrucAligParameters params)
			throws StructureException {
		reset();
		this.params = params;

		Chain c1 = s1.getPolyChainByPDB(chainId1);
		Chain c2 = s2.getPolyChainByPDB(chainId2);

		Structure s3 = new StructureImpl();
		s3.addChain(c1);

		Structure s4 = new StructureImpl();
		s4.addChain(c2);

		Atom[] ca1 = getAlignmentAtoms(s3);
		Atom[] ca2 = getAlignmentAtoms(s4);

		notifyStartingAlignment(s1.getName(), ca1, s2.getName(), ca2);
		align(ca1, ca2, params);
	}
675104
@Override
    public String getResult() {
        final List<String> result = new ArrayList<>();
        for (final Value t: value) {
            final String token = t.value.trim();
            // Pieces which are surrounded with braces are extension points.
            if (token.startsWith("{") && token.endsWith("}")) {
                final String extension = token.substring(1, token.length() - 1);
                final String extensionInputs = Integrator.getValue(featureTable, extension);
                if (extensionInputs != null) {
                    result.add(extensionInputs);
                }
            } else {
                result.add(token);
            }
        }
        if (!result.isEmpty()) {
            return StringUtils.join(result, ",");
        } else {
            return "";
        }
    }
910048
public static CeSymmResult analyzeLevel(Atom[] atoms,
			CESymmParameters params) throws StructureException {

		if (atoms.length < 1)
			throw new IllegalArgumentException("Empty Atom array given.");

		CeSymmResult result = align(atoms, params);

		if (result.isRefined()) {
			// STEP 5: symmetry alignment optimization
			if (result.getParams().getOptimization()) {
				try {
					MultipleAlignment msa = result.getMultipleAlignment();
					SymmOptimizer optimizer = new SymmOptimizer(result);
					msa = optimizer.optimize();
					result.setMultipleAlignment(msa);
				} catch (RefinerFailedException e) {
					logger.debug("Optimization failed:" + e.getMessage());
				}
			}
		}
		return result;
	}
948666
@Override
	public String colorBySymmetry() {
		// TODO needs some refactoring
		String pointGroup = rotationGroup.getPointGroup();
		QuatSymmetrySubunits subunits = rotationAxisAligner.getSubunits();
		List<Integer> modelNumbers = subunits.getModelNumbers();
		List<String> chainIds = subunits.getChainIds();
		List<List<Integer>> orbits = rotationAxisAligner.getOrbits();

		int n = subunits.getSubunitCount();
		int fold = rotationGroup.getRotation(0).getFold();

		Map<Color4f, List<String>> colorMap = new HashMap<Color4f, List<String>>();

		// Simple Cn symmetry
		if (pointGroup.startsWith("C") && n == fold) {
			colorMap = getCnColorMap();
			// complex cases
		} else if ((pointGroup.startsWith("D") && orbits.size() > 2) ||
				pointGroup.equals("T")|| pointGroup.equals("O") || pointGroup.equals("I")) {
			int nColor = 0;
			if (orbits.size() % 2 == 0) {
				nColor = orbits.size()/2;
			} else {
				nColor = (orbits.size() + 1)/2;
			}
			Color4f[] colors = getSymmetryColors(nColor);

			for (int i = 0; i < orbits.size(); i++) {
				int colorIndex = i;

				// reverse colors once the center of the structure has been reached
				if (i >= nColor) {
					colorIndex = orbits.size() - 1 - i;
				}
				Color4f c = colors[colorIndex];
				List<String> ids = colorMap.get(c);
				if (ids == null) {
					ids = new ArrayList<String>();
					colorMap.put(c,  ids);
				}
				for (int subunit: orbits.get(i)) {
					String id = getChainSpecification(modelNumbers, chainIds, subunit);
					ids.add(id);
				}
			}

			// Simple Dn symmetry
		} else {
			Color4f[] colors = getSymmetryColors(orbits.size());

			for (int i = 0; i < orbits.size(); i++) {
				Color4f c = new Color4f(colors[i]);
				List<String> ids = colorMap.get(c);
				if (ids == null) {
					ids = new ArrayList<String>();
					colorMap.put(c,  ids);
				}
				List<Integer> orbit = orbits.get(i);
				for (int j = 0; j < orbit.size(); j++) {
					String id = getChainSpecification(modelNumbers, chainIds, orbit.get(j));
					ids.add(id);
				}
			}
		}

		return defaultColoring + getJmolColorScript(colorMap) + getJmolLigandScript();
	}
459594
private void prepareForOutput(Polygon2D_F64 imageShape, Result result) {
		// the rotation estimate, apply in counter clockwise direction
		// since result.rotation is a clockwise rotation in the visual sense, which
		// is CCW on the grid
		int rotationCCW = (4-result.rotation)%4;
		for (int j = 0; j < rotationCCW; j++) {
			UtilPolygons2D_F64.shiftUp(imageShape);
		}

		// save the results for output
		FoundFiducial f = found.grow();
		f.id = result.which;

		for (int i = 0; i < 4; i++) {
			Point2D_F64 a = imageShape.get(i);
			undistToDist.compute(a.x, a.y, f.distortedPixels.get(i));
		}
	}
908936
public NavigationResultBuilder add(NavigationResult result)
   {
      if (result != null && result.getNext() != null)
      {
         entries.addAll(Arrays.asList(result.getNext()));
      }
      return this;
   }