/// <summary> /// Creates a new <see cref="Residue" /> object. /// </summary> /// <param name="molecule">The molecule this residue belongs to.</param> /// <param name="atom">An atom in the residue. This is needed to obtain residue properties /// since there is no corresponding PDB file record.</param> internal Residue(Molecule molecule, Atom atom) { this.molecule = molecule; this.molecule.ShowCartoonChanged += this.MoleculeShowCartoonChanged; this.residueName = atom.ResidueName; this.chainIdentifier = atom.ChainIdentifier; this.residueSequenceNumber = atom.ResidueSequenceNumber; this.atoms = new List<Atom>(); this.atoms.Add(atom); this.residueIdentifier = Residue.GetResidueIdentifier(this.residueName); this.residueColor = Residue.GetResidueColor(this.residueName); this.structureColor = this.residueIdentifier != "O" ? Colors.LightGray : Colors.Red; this.colorScheme = ColorScheme.Structure; this.residueStripItems = new List<ResidueStripItem>(); foreach (char character in this.residueIdentifier) { ResidueStripItem residueStripItem = new ResidueStripItem(character.ToString()); residueStripItem.Residue = this; this.residueStripItems.Add(residueStripItem); } this.model = new Model3DGroup(); this.UpdateColorView(); }
/// <summary> /// Creates the 3D model for stick that represents a bond. /// </summary> /// <param name="modelGroup">The Model3DGroup that will contain the stick.</param> /// <param name="atom">The other atom this atom is bonded with.</param> /// <param name="distance">The distance to the other bonded atom.</param> protected void CreateBondStick(Model3DGroup modelGroup, Atom atom, double distance) { GeometryModel3D stickModel = new GeometryModel3D(); stickModel.Geometry = distance > 2 ? Stick.LongMesh : Stick.ShortMesh; stickModel.Material = this.diffuseMaterial; modelGroup.Children.Add(stickModel); Transform3DGroup transformGroup = new Transform3DGroup(); stickModel.Transform = transformGroup; ScaleTransform3D scaleTransform = new ScaleTransform3D(); scaleTransform.ScaleX = distance / 2; transformGroup.Children.Add(scaleTransform); RotateTransform3D rotationTransfrom = new RotateTransform3D(); transformGroup.Children.Add(rotationTransfrom); Vector3D orientationVector = new Vector3D(1, 0, 0); Vector3D differenceVector = new Vector3D(atom.position.X - this.position.X, atom.position.Y - this.position.Y, atom.position.Z - this.position.Z); AxisAngleRotation3D rotation = new AxisAngleRotation3D(); rotation.Angle = Vector3D.AngleBetween(orientationVector, differenceVector); rotation.Axis = Vector3D.CrossProduct(orientationVector, differenceVector); if (rotation.Axis.LengthSquared > 0) rotationTransfrom.Rotation = rotation; transformGroup.Children.Add(this.translationTransform); }
private Point? GetViewportCoordinatePoint3Ds(Atom atom) { Point3D position = this.Molecule.MoleculeTransform.Value.Transform(atom.Position); position = this.moleculeVisual.Transform.Value.Transform(position); if (position.Z > cameraOffset - ((ProjectionCamera)this.viewport.Camera).NearPlaneDistance) return null; if (position.Z < cameraOffset - ((ProjectionCamera)this.viewport.Camera).FarPlaneDistance) return null; double a = Math.Tan(Math.PI / 8) * (cameraOffset - position.Z); double x = (position.X / a + 1) * this.ActualWidth / 2; double y = (1 - position.Y / a * this.ActualWidth / this.ActualHeight) * this.ActualHeight / 2; return new Point(x, y); }