Example #1
0
        /// <summary>
        /// Initialize the surface, generating the points on the accessible surface
        /// area of each atom as well as calculating the surface area of each atom.
        /// </summary>
        private void Init()
        {
            // invariants
            foreach (var atom in atoms)
            {
                if (atom.Point3D == null)
                {
                    throw new ArgumentException("One or more atoms had no 3D coordinate set");
                }
            }

            // get r_f and geometric center
            var    cp        = new Vector3(0, 0, 0);
            double maxRadius = 0;

            foreach (var atom in atoms)
            {
                var vdwr = PeriodicTable.GetVdwRadius(atom.Symbol).Value;
                if (vdwr + solventRadius > maxRadius)
                {
                    maxRadius = PeriodicTable.GetVdwRadius(atom.Symbol).Value + solventRadius;
                }

                cp.X = cp.X + atom.Point3D.Value.X;
                cp.Y = cp.Y + atom.Point3D.Value.Y;
                cp.Z = cp.Z + atom.Point3D.Value.Z;
            }
            cp.X = cp.X / atoms.Length;
            cp.Y = cp.Y / atoms.Length;
            cp.Z = cp.Z / atoms.Length;

            // do the tesselation
            var tess = new Tessellate("ico", tesslevel);

            tess.DoTessellate();
            Trace.TraceInformation($"Got tesselation, number of triangles = {tess.GetNumberOfTriangles()}");

            // get neighbor list
            var nbrlist = new NeighborList(atoms, maxRadius + solventRadius);

            Trace.TraceInformation("Got neighbor list");

            // loop over atoms and get surface points
            this.surfPoints = new List <Vector3> [atoms.Length];
            this.areas      = new double[atoms.Length];
            this.volumes    = new double[atoms.Length];

            for (int i = 0; i < atoms.Length; i++)
            {
                var pointDensity = tess.GetNumberOfTriangles() * 3;
                var points       = AtomicSurfacePoints(nbrlist, i, atoms[i], tess);
                TranslatePoints(i, points, pointDensity, atoms[i], cp);
            }
            Trace.TraceInformation("Obtained points, areas and volumes");
        }