diff --git a/src/main/java/org/openmolecules/fx/viewer3d/V3DScene.java b/src/main/java/org/openmolecules/fx/viewer3d/V3DScene.java index 0f5146e..15c65c6 100755 --- a/src/main/java/org/openmolecules/fx/viewer3d/V3DScene.java +++ b/src/main/java/org/openmolecules/fx/viewer3d/V3DScene.java @@ -184,7 +184,7 @@ private void initializeDragAndDrop() { } ); } - private void showMessage(String msg) { + public void showMessage(String msg) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information"); alert.setHeaderText(null); diff --git a/src/main/java/org/openmolecules/fx/viewerapp/StartOptions.java b/src/main/java/org/openmolecules/fx/viewerapp/StartOptions.java index 3eabb6f..d903cdb 100755 --- a/src/main/java/org/openmolecules/fx/viewerapp/StartOptions.java +++ b/src/main/java/org/openmolecules/fx/viewerapp/StartOptions.java @@ -20,12 +20,13 @@ package org.openmolecules.fx.viewerapp; -import com.actelion.research.chem.Coordinates; -import com.actelion.research.chem.IDCodeParser; -import com.actelion.research.chem.Molecule3D; -import com.actelion.research.chem.StereoMolecule; +import com.actelion.research.chem.*; import com.actelion.research.chem.conf.Conformer; +import com.actelion.research.chem.io.pdb.parser.PDBCoordEntryFile; +import com.actelion.research.chem.io.pdb.parser.PDBFileParser; +import com.actelion.research.chem.io.pdb.parser.StructureAssembler; import com.actelion.research.util.Platform; +import javafx.scene.control.ChoiceDialog; import javafx.scene.paint.Color; import javafx.scene.shape.MeshView; import org.openmolecules.chem.conf.gen.ConformerGenerator; @@ -36,6 +37,10 @@ import org.openmolecules.fx.viewer3d.V3DScene; import org.openmolecules.pdb.MMTFParser; +import java.io.File; +import java.util.List; +import java.util.Map; + public class StartOptions { // home path used when loading pdb file from disk assuming OS is either Linux or MacOSX private static final String HOME_PATH = Platform.isLinux() ? "~/" : "~/Documents/"; @@ -300,13 +305,13 @@ public class StartOptions { private static final double SURFACE_SATURATION = 0.15; // must be less than 1.0 - SURFACE_BRIGHTNESS private int mode; - private String pdbEntryCode,mmtfFile; + private String pdbEntryCode,pdbFile; private boolean cropLigand; - public StartOptions(int mode, String pdbEntryCode, String mmtfFile, boolean cropLigand) { + public StartOptions(int mode, String pdbEntryCode, String pdbFile, boolean cropLigand) { this.mode = mode; this.pdbEntryCode = pdbEntryCode; - this.mmtfFile = mmtfFile; + this.pdbFile = pdbFile; this.cropLigand = cropLigand; } @@ -345,70 +350,92 @@ else if (mode == 5) private void loadPDBEntry(V3DScene scene) { try { - Molecule3D[] mol = null; - if (mmtfFile != null) - mol = MMTFParser.getStructureFromFile(mmtfFile, pdbEntryCode, MMTFParser.MODE_SPLIT_CHAINS); - else if (!pdbEntryCode.isEmpty()) - mol = MMTFParser.getStructureFromName(pdbEntryCode, MMTFParser.MODE_SPLIT_CHAINS); + PDBFileParser parser = new PDBFileParser(); + PDBCoordEntryFile entryFile = (pdbFile != null) ? + parser.parse(new File(pdbFile)) + : (!pdbEntryCode.isEmpty()) ? parser.getFromPDB(pdbEntryCode) : null; + + if (entryFile == null) { + scene.showMessage("Unexpectedly didn't get PDB entry."); + return; + } - if (mol != null) { -// mMoleculePanel.setShowStructure(false); - MMTFParser.centerMolecules(mol); - - V3DMolecule ligand = null; - int ligandIndex = -2; // will be -1, if we have more than one potential ligands - for (int i=0; i 100) - largeMoleculeCount++; - - Color[] surfaceColor = new Color[largeMoleculeCount]; - double inc = 2.0 * Math.PI / largeMoleculeCount; - double shift = 2.0 * Math.PI / 3.0; - for (int i=0; i> map = entryFile.extractMols(false); + List ligands = map.get(StructureAssembler.LIGAND_GROUP); + if (ligands == null || ligands.isEmpty()) { + map = entryFile.extractMols(true); + ligands = map.get(StructureAssembler.LIGAND_GROUP); + if (ligands != null && !ligands.isEmpty()) + scene.showMessage("Only covalent ligand(s) were found and disconnected from the protein structure."); + } + + List proteins = map.get(StructureAssembler.PROTEIN_GROUP); + if (proteins == null || proteins.isEmpty()) { + scene.showMessage("No proteins found in file."); + return; + } + + Molecule3D ligand = null; + + if (ligands != null && !ligands.isEmpty()) { + int index = -1; + if (ligands.size() == 1) { + index = 0; } - V3DRotatableGroup complex = new V3DRotatableGroup(pdbEntryCode); - System.out.println(pdbEntryCode); - scene.addGroup(complex); - int largeMoleculeIndex = 0; - int id = V3DMolecule.getNextID(); - for (int i=0; i 100); - - V3DMolecule vm; - if (isWater) - vm = new V3DMolecule(mol[i], MoleculeArchitect.ConstructionMode.STICKS, MoleculeArchitect.HydrogenMode.ALL, id, V3DMolecule.MoleculeRole.SOLVENT,true); - else if (isLargeMolecule) - vm = new V3DMolecule(mol[i], MoleculeArchitect.ConstructionMode.WIRES, MoleculeArchitect.HYDROGEN_MODE_DEFAULT, - V3DMolecule.SurfaceMode.FILLED, SurfaceMesh.SURFACE_COLOR_DONORS_ACCEPTORS, surfaceColor[largeMoleculeIndex++], 0.5, V3DMolecule.getNextID(),V3DMolecule.MoleculeRole.MACROMOLECULE,true); - else - vm = new V3DMolecule(mol[i], MoleculeArchitect.ConstructionMode.BALL_AND_STICKS, MoleculeArchitect.HydrogenMode.ALL,id,V3DMolecule.MoleculeRole.LIGAND, true); - vm.setID(id); - if (i == ligandIndex) - ligand = vm; - -// millis = printDelay(millis); -// System.out.print("adding molecule to scene... "); - - scene.addMolecule(vm,complex); -// millis = printDelay(millis); + else { + String[] ligandName = new String[ligands.size()]; + for (int i=0; i dialog = new ChoiceDialog<>(ligandName[0], ligandName); + dialog.titleProperty().set("Select one of multiple ligands:"); + dialog.showAndWait(); + String name = dialog.getSelectedItem(); + if (name != null) + index = Integer.parseInt(name.substring(0, name.indexOf(':')))-1; } - if (ligand != null && cropLigand) { - scene.crop(ligand, 10.0); + if ((index != -1)) + ligand = ligands.get(index); + } + +// mMoleculePanel.setShowStructure(false); +// MMTFParser.centerMolecules(mol); + + Color[] surfaceColor = new Color[proteins.size()]; + double inc = 2.0 * Math.PI / proteins.size(); + double shift = 2.0 * Math.PI / 3.0; + for (int i=0; i solvents = map.get(StructureAssembler.SOLVENT_GROUP); + for (Molecule3D mol : solvents) { + V3DMolecule vm = new V3DMolecule(mol, MoleculeArchitect.ConstructionMode.STICKS, MoleculeArchitect.HydrogenMode.ALL, V3DMolecule.getNextID(), V3DMolecule.MoleculeRole.SOLVENT,true); + scene.addMolecule(vm, complex); + } + + if (ligand != null) { + V3DMolecule vm = new V3DMolecule(ligand, MoleculeArchitect.ConstructionMode.BALL_AND_STICKS, MoleculeArchitect.HydrogenMode.ALL,V3DMolecule.getNextID(),V3DMolecule.MoleculeRole.LIGAND, true); + scene.addMolecule(vm, complex); + + if (cropLigand) { + scene.crop(vm, 10.0); scene.optimizeView(); } } @@ -417,6 +444,19 @@ else if (isLargeMolecule) } } + private Map> addProteinAndLigand(PDBCoordEntryFile entryFile, V3DScene scene) { + Map> map = entryFile.extractMols(false); + List ligands = map.get(StructureAssembler.LIGAND_GROUP); + if (ligands == null || ligands.isEmpty()) { + map = entryFile.extractMols(true); + ligands = map.get(StructureAssembler.LIGAND_GROUP); + if (ligands != null && !ligands.isEmpty()) + scene.showMessage("Only covalent ligand(s) were found and disconnected from the protein structure."); + } + + return map; + } + private void testMolecules(V3DScene scene) { for (int i = 0; i < TEST_POSITIONS_13.length; i++) { double[] coord = TEST_POSITIONS_13[i];