Ejemplo n.º 1
0
        /// <summary>
        /// Builds the 3D model for the cartoon view a the given residue.
        /// </summary>
        /// <param name="residue">A residue.</param>
        /// <param name="initialColor">The residue's current color.</param>
        internal Cartoon(Residue residue, Color initialColor)
        {
            this.residue = residue;

            this.materialGroup = new MaterialGroup();

            this.diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(initialColor));
            this.materialGroup.Children.Add(diffuseMaterial);

            SpecularMaterial specularMaterial = new SpecularMaterial();
            specularMaterial.Brush = new SolidColorBrush(Color.FromArgb(192, 255, 255, 255));
            specularMaterial.SpecularPower = 50;
            this.materialGroup.Children.Add(specularMaterial);

            this.model = new Model3DGroup();

            this.residue.Ribbon.GetResidueSpline(this.residue, out this.ribbonPoints,
                out this.torsionVectors, out this.normalVectors);

            if (this.residue.IsHelix)
            {
                this.AddTube(Cartoon.helixWidth, Cartoon.helixHeight);

                if (this.residue.IsStructureStart)
                    this.AddTubeCap(Cartoon.helixWidth, Cartoon.helixHeight);

                if (this.residue.IsStructureEnd)
                    this.AddTubeCap(Cartoon.helixWidth, Cartoon.helixHeight);
            }
            else if (this.residue.IsSheet)
            {
                this.AddSheet();

                if (this.residue.IsStructureStart || this.residue.IsStructureEnd)
                    this.AddSheetCap();
            }
            else
            {
                this.AddTube(Cartoon.turnWidth, Cartoon.turnWidth);

                if (this.residue.IsStructureStart)
                    this.AddTubeCap(Cartoon.turnWidth, Cartoon.turnWidth);

                if (this.residue.IsStructureEnd)
                    this.AddTubeCap(Cartoon.turnWidth, Cartoon.turnWidth);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all of the values that represent the spline for a particular residue.
        /// </summary>
        /// <param name="residue">A residue in the corresponding secondary structure.</param>
        /// <param name="residueRibbonPoints">A list control points for the spline.</param>
        /// <param name="residueTorsionVectors">A list of the torsion vectors for the
        /// spline.</param>
        /// <param name="residueNormalVectors">A list of the normal vectors for the spline.</param>
        internal void GetResidueSpline(Residue residue, out List<Point3D> residueRibbonPoints,
            out List<Vector3D> residueTorsionVectors, out List<Vector3D> residueNormalVectors)
        {
            residueRibbonPoints = new List<Point3D>();
            residueTorsionVectors = new List<Vector3D>();
            residueNormalVectors = new List<Vector3D>();

            int startIndex = this.residues.IndexOf(residue) * Ribbon.linearSegmentCount;

            for (int i = startIndex; i <= startIndex + Ribbon.linearSegmentCount; i++)
            {
                residueRibbonPoints.Add(this.ribbonPoints[i]);
                residueTorsionVectors.Add(this.torsionVectors[i]);
                residueNormalVectors.Add(this.normalVectors[i]);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called by the constructor to create <see cref="Residue"/> objects and group their
        /// constituent atoms.
        /// </summary>
        private void CreateResidues()
        {
            this.residues = new List<Residue>();

            Residue residue = null;

            foreach (Atom atom in this.atoms)
            {
                if (residue == null || atom.ResidueSequenceNumber != residue.ResidueSequenceNumber ||
                    atom.ChainIdentifier != residue.ChainIdentifier)
                {
                    residue = new Residue(this, atom);
                    this.residues.Add(residue);
                }
                else
                {
                    residue.Atoms.Add(atom);
                }

                atom.Residue = residue;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Static method for parsing atom entries in a pdb file and instantiating the correct
        /// <see cref="Atom" /> subclass.
        /// </summary>
        /// <param name="molecule">The molecule this atom belongs to.</param>
        /// <param name="pdbLine">An atom entry from a pdb file.</param>
        /// <returns>An instance of an <see cref="Atom" /> subclass.</returns>
        internal static Atom CreateAtom(Molecule molecule, string pdbLine)
        {
            Atom atom;

            string atomName    = pdbLine.Substring(12, 4).Trim();
            string residueName = pdbLine.Substring(17, 3).Trim();

            if (Residue.IsAminoName(residueName))
            {
                if (atomName == "CA")
                {
                    atom = new CAlpha();
                }
                else
                {
                    atom = new ChainAtom();
                }
            }
            else
            {
                if (residueName == "HOH")
                {
                    atom = new Water();
                }
                else
                {
                    atom = new HetAtom();
                }
            }

            atom.molecule = molecule;

            atom.bonds = new Dictionary <Atom, double>();

            atom.atomName    = pdbLine.Substring(12, 4).Trim();
            atom.residueName = pdbLine.Substring(17, 3).Trim();

            atom.residueSequenceNumber = Convert.ToInt32(pdbLine.Substring(22, 4));

            atom.chainIdentifier = pdbLine.Substring(21, 1);
            if (atom.residueName == "HOH")
            {
                atom.chainIdentifier = "";
            }
            else if (atom.chainIdentifier == " ")
            {
                atom.chainIdentifier = "1";
            }

            double x = Double.Parse(pdbLine.Substring(30, 8));
            double y = Double.Parse(pdbLine.Substring(38, 8));
            double z = Double.Parse(pdbLine.Substring(46, 8));

            atom.position = new Point3D(x, y, z);

            atom.temperatureFactor = Double.Parse(pdbLine.Substring(60, 6));

            if (atom.atomName.StartsWith("C"))
            {
                atom.atomColor = Colors.LightGray;
            }
            else if (atom.atomName.StartsWith("N"))
            {
                atom.atomColor = Colors.Blue;
            }
            else if (atom.atomName.StartsWith("O"))
            {
                atom.atomColor = Colors.Red;
            }
            else if (atom.atomName.StartsWith("H"))
            {
                atom.atomColor = Colors.Purple;
            }
            else if (atom.atomName.StartsWith("S"))
            {
                atom.atomColor = Colors.Yellow;
            }
            else
            {
                atom.atomColor = Colors.Green;
            }

            atom.structureColor = atom.atomColor;

            atom.colorScheme = ColorScheme.Structure;

            atom.diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(atom.atomColor));

            atom.model = new Model3DGroup();

            atom.translationTransform = new TranslateTransform3D(
                atom.position.X, atom.position.Y, atom.position.Z);

            atom.CreateSelectionSphere();

            return(atom);
        }