public /*Chem*/ Frame(Org.OpenScience.CDK.Interfaces.IChemFile chemFile, Device graphicsDevice) { shapes = new Shape[JmolConstants.SHAPE_MAX]; this.g3d = new NuGraphics3D(graphicsDevice); this.frameRenderer = new FrameRenderer(); for (int i = MAX_BONDS_LENGTH_TO_CACHE; --i > 0;) // .GT. 0 { freeBonds[i] = new Bond[MAX_NUM_TO_CACHE][]; } // convert to jmol native mmset = new Mmset(this); // set properties mmset.ModelSetProperties = new System.Collections.Specialized.NameValueCollection(); // init build currentModelIndex = -1; currentModel = null; currentChainID = '\uFFFF'; currentChain = null; currentGroupSequenceNumber = -1; currentGroupInsertionCode = '\uFFFF'; int atomCountEstimate = 0; for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++) { atomCountEstimate += chemModel.SetOfMolecules.AtomContainers[atomC].AtomCount; } } } if (atomCountEstimate <= 0) { atomCountEstimate = ATOM_GROWTH_INCREMENT; } atoms = new Atom[atomCountEstimate]; bonds = new Bond[2 * atomCountEstimate]; htAtomMap.Clear(); // translate IChemSequence[] into Model[] mmset.ModelCount = chemFile.ChemSequenceCount; for (int seq = 0; seq < chemFile.ChemSequenceCount; ++seq) { int modelNumber = seq + 1; string modelName = modelNumber.ToString(); NameValueCollection modelProperties = new NameValueCollection(); // FIXME: Loading property values mmset.setModelNameNumberProperties(seq, modelName, modelNumber, modelProperties); } // translate Atoms Dictionary <Org.OpenScience.CDK.Interfaces.IAtom, Atom> atomsList = new Dictionary <Org.OpenScience.CDK.Interfaces.IAtom, Atom>(); //try //{ for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++) { for (int atomIdx = 0; atomIdx < chemModel.SetOfMolecules.AtomContainers[atomC].AtomCount; atomIdx++) { Org.OpenScience.CDK.Interfaces.IAtom atom = chemModel.SetOfMolecules.AtomContainers[atomC].Atoms[atomIdx]; sbyte elementNumber = (sbyte)atom.AtomicNumber; if (elementNumber <= 0) { elementNumber = JmolConstants.elementNumberFromSymbol(atom.Symbol); } char alternateLocation = '\0'; int sequenceNumber = int.MinValue; char groupInsertionCode = '\0'; string atomName = null; string group3Name = null; char chainID = '\0'; if (atom is PDBAtom) { PDBAtom pdbAtom = (PDBAtom)atom; if (pdbAtom.ResSeq != null && pdbAtom.ResSeq.Length > 0) { sequenceNumber = int.Parse(pdbAtom.ResSeq); } if (pdbAtom.ICode != null && pdbAtom.ICode.Length > 0) { groupInsertionCode = pdbAtom.ICode[0]; } atomName = pdbAtom.Name; group3Name = pdbAtom.ResName; if (pdbAtom.ChainID != null && pdbAtom.ChainID.Length >= 1) { chainID = pdbAtom.ChainID[0]; } } else { atomName = atom.AtomTypeName; } atomsList[atom] = AddAtom(model, atom, elementNumber, atomName, atom.getFormalCharge(), (float)atom.getCharge(), 100, float.NaN, (float)atom.X3d, (float)atom.Y3d, (float)atom.Z3d, false, int.MinValue, chainID, group3Name, sequenceNumber, groupInsertionCode, float.NaN, float.NaN, float.NaN, alternateLocation, null); } } } } //} //catch (Exception e) //{ // throw new ApplicationException("Problem translating atoms", e); //} fileHasHbonds = false; // translate bonds try { for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++) { for (int bondIdx = 0; bondIdx < chemModel.SetOfMolecules.AtomContainers[atomC].Bonds.Length; bondIdx++) { Org.OpenScience.CDK.Interfaces.IBond bond = chemModel.SetOfMolecules.AtomContainers[atomC].Bonds[bondIdx]; Org.OpenScience.CDK.Interfaces.IAtom[] cdkAtoms = bond.getAtoms(); // locate translated atoms Atom atom1, atom2; atomsList.TryGetValue(cdkAtoms[0], out atom1); atomsList.TryGetValue(cdkAtoms[1], out atom2); bondAtoms(atom1, atom2, (int)bond.Order); } } } } } catch (Exception e) { throw new ApplicationException("Problem translating bonds", e); } atomsList.Clear(); // translate structures of PDBPolymer only for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; foreach (Org.OpenScience.CDK.Interfaces.IMolecule molecule in chemModel.SetOfMolecules.Molecules) { if (molecule is PDBPolymer) { PDBPolymer pdbPolymer = (PDBPolymer)molecule; if (pdbPolymer.Structures != null && pdbPolymer.Structures.Count > 0) { structuresDefined = true; foreach (PDBStructure pdbStruct in pdbPolymer.Structures) { structuresDefined = true; mmset.defineStructure(pdbStruct.StructureType, pdbStruct.StartChainID, pdbStruct.StartSequenceNumber, pdbStruct.StartInsertionCode, pdbStruct.EndChainID, pdbStruct.EndSequenceNumber, pdbStruct.EndInsertionCode); } } } } } } autoBond(null, null); // build groups FinalizeGroupBuild(); BuildPolymers(); Freeze(); finalizeBuild(); // create ribbon shapes try { setShapeSize(JmolConstants.SHAPE_RIBBONS, -1, new BitArray(0)); setShapeSize(JmolConstants.SHAPE_CARTOON, -1, new BitArray(0)); } catch (Exception) { } }
public Model(Mmset mmset, int modelIndex, string modelTag) { this.mmset = mmset; this.modelIndex = modelIndex; this.modelTag = modelTag; }
public override void initShape() { mmset = frame.mmset; }
public /*Chem*/Frame(Org.OpenScience.CDK.Interfaces.IChemFile chemFile, Device graphicsDevice) { shapes = new Shape[JmolConstants.SHAPE_MAX]; this.g3d = new NuGraphics3D(graphicsDevice); this.frameRenderer = new FrameRenderer(); for (int i = MAX_BONDS_LENGTH_TO_CACHE; --i > 0; ) // .GT. 0 freeBonds[i] = new Bond[MAX_NUM_TO_CACHE][]; // convert to jmol native mmset = new Mmset(this); // set properties mmset.ModelSetProperties = new System.Collections.Specialized.NameValueCollection(); // init build currentModelIndex = -1; currentModel = null; currentChainID = '\uFFFF'; currentChain = null; currentGroupSequenceNumber = -1; currentGroupInsertionCode = '\uFFFF'; int atomCountEstimate = 0; for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++) { atomCountEstimate += chemModel.SetOfMolecules.AtomContainers[atomC].AtomCount; } } } if (atomCountEstimate <= 0) atomCountEstimate = ATOM_GROWTH_INCREMENT; atoms = new Atom[atomCountEstimate]; bonds = new Bond[2 * atomCountEstimate]; htAtomMap.Clear(); // translate IChemSequence[] into Model[] mmset.ModelCount = chemFile.ChemSequenceCount; for (int seq = 0; seq < chemFile.ChemSequenceCount; ++seq) { int modelNumber = seq + 1; string modelName = modelNumber.ToString(); NameValueCollection modelProperties = new NameValueCollection(); // FIXME: Loading property values mmset.setModelNameNumberProperties(seq, modelName, modelNumber, modelProperties); } // translate Atoms Dictionary<Org.OpenScience.CDK.Interfaces.IAtom, Atom> atomsList = new Dictionary<Org.OpenScience.CDK.Interfaces.IAtom, Atom>(); //try //{ for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++) { for (int atomIdx = 0; atomIdx < chemModel.SetOfMolecules.AtomContainers[atomC].AtomCount; atomIdx++) { Org.OpenScience.CDK.Interfaces.IAtom atom = chemModel.SetOfMolecules.AtomContainers[atomC].Atoms[atomIdx]; sbyte elementNumber = (sbyte)atom.AtomicNumber; if (elementNumber <= 0) elementNumber = JmolConstants.elementNumberFromSymbol(atom.Symbol); char alternateLocation = '\0'; int sequenceNumber = int.MinValue; char groupInsertionCode = '\0'; string atomName = null; string group3Name = null; char chainID = '\0'; if (atom is PDBAtom) { PDBAtom pdbAtom = (PDBAtom)atom; if (pdbAtom.ResSeq != null && pdbAtom.ResSeq.Length > 0) sequenceNumber = int.Parse(pdbAtom.ResSeq); if (pdbAtom.ICode != null && pdbAtom.ICode.Length > 0) groupInsertionCode = pdbAtom.ICode[0]; atomName = pdbAtom.Name; group3Name = pdbAtom.ResName; if (pdbAtom.ChainID != null && pdbAtom.ChainID.Length >= 1) chainID = pdbAtom.ChainID[0]; } else atomName = atom.AtomTypeName; atomsList[atom] = AddAtom(model, atom, elementNumber, atomName, atom.getFormalCharge(), (float)atom.getCharge(), 100, float.NaN, (float)atom.X3d, (float)atom.Y3d, (float)atom.Z3d, false, int.MinValue, chainID, group3Name, sequenceNumber, groupInsertionCode, float.NaN, float.NaN, float.NaN, alternateLocation, null); } } } } //} //catch (Exception e) //{ // throw new ApplicationException("Problem translating atoms", e); //} fileHasHbonds = false; // translate bonds try { for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++) { for (int bondIdx = 0; bondIdx < chemModel.SetOfMolecules.AtomContainers[atomC].Bonds.Length; bondIdx++) { Org.OpenScience.CDK.Interfaces.IBond bond = chemModel.SetOfMolecules.AtomContainers[atomC].Bonds[bondIdx]; Org.OpenScience.CDK.Interfaces.IAtom[] cdkAtoms = bond.getAtoms(); // locate translated atoms Atom atom1, atom2; atomsList.TryGetValue(cdkAtoms[0], out atom1); atomsList.TryGetValue(cdkAtoms[1], out atom2); bondAtoms(atom1, atom2, (int)bond.Order); } } } } } catch (Exception e) { throw new ApplicationException("Problem translating bonds", e); } atomsList.Clear(); // translate structures of PDBPolymer only for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++) { for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++) { Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model]; foreach (Org.OpenScience.CDK.Interfaces.IMolecule molecule in chemModel.SetOfMolecules.Molecules) { if (molecule is PDBPolymer) { PDBPolymer pdbPolymer = (PDBPolymer)molecule; if (pdbPolymer.Structures != null && pdbPolymer.Structures.Count > 0) { structuresDefined = true; foreach (PDBStructure pdbStruct in pdbPolymer.Structures) { structuresDefined = true; mmset.defineStructure(pdbStruct.StructureType, pdbStruct.StartChainID, pdbStruct.StartSequenceNumber, pdbStruct.StartInsertionCode, pdbStruct.EndChainID, pdbStruct.EndSequenceNumber, pdbStruct.EndInsertionCode); } } } } } } autoBond(null, null); // build groups FinalizeGroupBuild(); BuildPolymers(); Freeze(); finalizeBuild(); // create ribbon shapes try { setShapeSize(JmolConstants.SHAPE_RIBBONS, -1, new BitArray(0)); setShapeSize(JmolConstants.SHAPE_CARTOON, -1, new BitArray(0)); } catch (Exception) { } }
public Frame(/*Viewer viewer, JmolAdapter adapter,*/ object clientFile) { InitBlock(); //this.viewer = viewer; //this.adapter = adapter; //long timeBegin = System.currentTimeMillis(); //string fileTypeName = adapter.getFileTypeName(clientFile); // NOTE: these strings are interned and are lower case // therefore, we can do == comparisions against string constants // if (modelSetTypeName == "xyz") { } //this.modelSetTypeName = String.Intern(fileTypeName.ToLower()); mmset = new Mmset(this); //this.frameRenderer = viewer.FrameRenderer; //this.g3d = viewer.Graphics3D; //initializeBuild(adapter.getEstimatedAtomCount(clientFile)); /// <summary> /// crystal cell must come first, in case atom coordinates /// need to be transformed to fit in the crystal cell /// </summary> //fileCoordinatesAreFractional = adapter.coordinatesAreFractional(clientFile); //NotionalUnitcell = adapter.getNotionalUnitcell(clientFile); //PdbScaleMatrix = adapter.getPdbScaleMatrix(clientFile); //PdbScaleTranslate = adapter.getPdbScaleTranslate(clientFile); //ModelSetProperties = adapter.getAtomSetCollectionProperties(clientFile); //currentModelIndex = - 1; //int modelCount = adapter.getAtomSetCount(clientFile); //ModelCount = modelCount; //for (int i = 0; i < modelCount; ++i) //{ // int modelNumber = adapter.getAtomSetNumber(clientFile, i); // string modelName = adapter.getAtomSetName(clientFile, i); // if (modelName == null) // modelName = "" + modelNumber; // //UPGRADE_ISSUE: Class hierarchy differences between 'java.util.Properties' and 'System.Collections.Specialized.NameValueCollection' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'" // System.Collections.Specialized.NameValueCollection modelProperties = adapter.getAtomSetProperties(clientFile, i); // setModelNameNumberProperties(i, modelName, modelNumber, modelProperties); //} //for (JmolAdapter.AtomIterator iterAtom = adapter.getAtomIterator(clientFile); iterAtom.hasNext(); ) //{ // sbyte elementNumber = (sbyte) iterAtom.ElementNumber; // if (elementNumber <= 0) // elementNumber = JmolConstants.elementNumberFromSymbol(iterAtom.ElementSymbol); // char alternateLocation = iterAtom.AlternateLocationID; // if (alternateLocation != '\x0000' && alternateLocation != 'A') // continue; // addAtom(iterAtom.AtomSetIndex, iterAtom.UniqueID, elementNumber, iterAtom.AtomName, iterAtom.FormalCharge, iterAtom.PartialCharge, iterAtom.Occupancy, iterAtom.Bfactor, iterAtom.X, iterAtom.Y, iterAtom.Z, iterAtom.IsHetero, iterAtom.AtomSerial, iterAtom.ChainID, iterAtom.Group3, iterAtom.SequenceNumber, iterAtom.InsertionCode, iterAtom.VectorX, iterAtom.VectorY, iterAtom.VectorZ, alternateLocation, iterAtom.ClientAtomReference); //} //fileHasHbonds = false; //{ // JmolAdapter.BondIterator iterBond = adapter.getBondIterator(clientFile); // if (iterBond != null) // while (iterBond.hasNext()) // bondAtoms(iterBond.AtomUniqueID1, iterBond.AtomUniqueID2, iterBond.EncodedOrder); //} //JmolAdapter.StructureIterator iterStructure = adapter.getStructureIterator(clientFile); //if (iterStructure != null) // while (iterStructure.hasNext()) // defineStructure(iterStructure.StructureType, iterStructure.StartChainID, iterStructure.StartSequenceNumber, iterStructure.StartInsertionCode, iterStructure.EndChainID, iterStructure.EndSequenceNumber, iterStructure.EndInsertionCode); //doUnitcellStuff(); //doAutobond(); //finalizeGroupBuild(); //buildPolymers(); //freeze(); //long msToBuild = System.currentTimeMillis() - timeBegin; // System.out.println("Build a frame:" + msToBuild + " ms"); //adapter.finish(clientFile); //finalizeBuild(); //dumpAtomSetNameDiagnostics(clientFile); }