use of ffx.potential.parsers.MergeFilter in project ffx by mjschnie.
the class MainPanel method merge.
/**
* Merge two or more selected FSystem Nodes into one FSystem node. There are
* a few gotchas that need to be fixed
*
* @param nodesToMerge a {@link java.util.ArrayList} object.
*/
public void merge(ArrayList<MSNode> nodesToMerge) {
ArrayList<MSNode> activeNodes = new ArrayList<MSNode>();
for (MSNode node : nodesToMerge) {
if (node != null && !(node instanceof MSRoot)) {
activeNodes.add(node);
}
}
if (activeNodes.size() <= 1) {
return;
}
// Set up a structure to hold the new system
FFXSystem active = hierarchy.getActive();
File file = SystemFilter.version(hierarchy.getActive().getFile());
FFXSystem system = new FFXSystem(file, "Merge Result", active.getProperties());
system.setKeyFile(active.getKeyFile());
system.setKeywords(KeyFilter.open(active.getKeyFile()));
// Fill arrays with the atoms and bonds from the systems to be combined
ArrayList<Atom> mergedAtoms = new ArrayList<Atom>();
ArrayList<Bond> mergedBonds = new ArrayList<Bond>();
ArrayList<FFXSystem> systems = new ArrayList<FFXSystem>();
TransformGroup parentTransformGroup = null;
FFXSystem parentSystem;
Transform3D parentTransform3D = new Transform3D();
Vector3d parentPosition = new Vector3d();
Vector3d atomPosition = new Vector3d();
// TINKER Atom Numbers start at 1
int atomNum = 1;
Vector3d zero = new Vector3d(0.0, 0.0, 0.0);
for (MSNode m : activeNodes) {
parentSystem = (FFXSystem) m.getMSNode(FFXSystem.class);
if (parentSystem == null) {
return;
}
if (!systems.contains(parentSystem)) {
graphicsCanvas.updateSceneWait(parentSystem, false, true, RendererCache.ViewModel.WIREFRAME, false, null);
systems.add(parentSystem);
}
// Move each atom into the global frame by applying the System
// Transform to
// relative atomic position
parentTransformGroup = parentSystem.getOriginToRot();
parentTransformGroup.getTransform(parentTransform3D);
parentTransform3D.get(parentPosition);
parentTransform3D.setTranslation(zero);
// parentTransform3D.setScale(1.0d);
ArrayList<Atom> atoms = m.getAtomList();
ArrayList<ROLS> bonds = m.getBondList();
for (Atom atom : atoms) {
atom.removeFromParent();
atom.setXyzIndex(atomNum++);
mergedAtoms.add(atom);
atom.getV3D(atomPosition);
parentTransform3D.transform(atomPosition);
atomPosition.add(parentPosition);
atom.moveTo(atomPosition);
}
for (ROLS msm : bonds) {
Bond bond = (Bond) msm;
bond.removeFromParent();
mergedBonds.add((Bond) msm);
}
}
for (FFXSystem sys : systems) {
close(sys);
}
MergeFilter mergeFilter = new MergeFilter(system, mergedAtoms, mergedBonds);
UIFileOpener fileOpener = new UIFileOpener(mergeFilter, this);
if (fileOpenerThreads > 0) {
fileOpener.setNThreads(fileOpenerThreads);
}
Thread thread = new Thread(fileOpener);
thread.start();
}
Aggregations