diff --git a/src/main/java/org/openmolecules/fx/viewer3d/nodes/Ribbons.java b/src/main/java/org/openmolecules/fx/viewer3d/nodes/Ribbons.java
index 338b525..a42afcb 100644
--- a/src/main/java/org/openmolecules/fx/viewer3d/nodes/Ribbons.java
+++ b/src/main/java/org/openmolecules/fx/viewer3d/nodes/Ribbons.java
@@ -1,7 +1,28 @@
+/*
+ * FXMolViewer, showing and manipulating molecules and protein structures in 3D.
+ * Copyright (C) 2024 Thomas Sander
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * @author Thomas Sander
+ */
+
package org.openmolecules.fx.viewer3d.nodes;
import com.actelion.research.chem.Coordinates;
import com.actelion.research.chem.Molecule;
+import com.actelion.research.chem.Molecule3D;
import com.actelion.research.chem.StereoMolecule;
import javafx.collections.ObservableFloatArray;
import javafx.scene.image.Image;
@@ -59,22 +80,33 @@ public Ribbons(StereoMolecule mol, V3DMolecule mol3D) {
mMol = mol;
mColor = mMol3D.getColor();
- mResidueAtom = determineBackbone();
+ mResidueAtom = readBackbone(); // works, if mMol is Molecule3D from PDB entry
+ if (mResidueAtom == null)
+ mResidueAtom = determineBackbone();
+
mRibbonMesh = new MeshView[mResidueAtom.length];
+ }
+
+ private int[][][] readBackbone() {
+ if (!(mMol instanceof Molecule3D)
+ || mMol.getAllAtoms() == 0
+ || ((Molecule3D)mMol).getResSequence(0) == -1)
+ return null;
+
+ Molecule3D mol = (Molecule3D)mMol;
-/*
ArrayList atomsList = new ArrayList<>();
int[] atoms = null;
int previousResidue = -1;
int atomsFound = 0;
for (int atom=0; atom fragmentList = new ArrayList<>();
+ ArrayList residueList = new ArrayList<>();
// We split into fragments when either the chainID changes or when the
// residue-ID differs more than 1 from the previous residue. This happens,
// for instance, after cropping and parts of the protein are cut away.
int chainIDAtomType = 1; // we use C-alpha for chain-ID lookup
- ArrayList chainIDStartList = new ArrayList<>();
- if (mResidueAtom.length != 0) {
- chainIDStartList.add(0);
- int atomCA = mResidueAtom[0][chainIDAtomType];
- int lastResidue = mMol.getResSequence(atomCA);
- String lastChainID = mMol.getAtomChainId(atomCA);
- for (int i=1; i= 2)
+ fragmentList.add(residueList.toArray(new int[0][]));
+ residueList.clear();
+ }
+ residueList.add(atomsList.get(i));
lastResidue = residue;
lastChainID = chainID;
}
}
- mFirstResidueOfFragment = new int[chainIDStartList.size()];
- for (int i=0; i= 2)
+ fragmentList.add(residueList.toArray(new int[0][]));
- mRibbonMesh = new MeshView[mFirstResidueOfFragment.length];
-*/
+ return fragmentList.toArray(new int[0][][]);
}
/**
@@ -139,7 +173,9 @@ private int[][][] determineBackbone() {
while ((residueAtom = getPreviousResidue(residueList.get(0)[ATOM_TYPE_N], atomUsed)) != null)
residueList.add(0, residueAtom);
- fragmentList.add(residueList.toArray(new int[0][]));
+ if (residueList.size() >= 2)
+ fragmentList.add(residueList.toArray(new int[0][]));
+
residueList.clear();
}
}