private static int GetIDWNeighbors(double[] InCellPoint, ref KDTreeDLL.KDTree InPointsTree, ref double[][] InPoints, out int[] Neighbors, IDWNeighborhoodType NeighborhoodType, int NeighborhoodCount, double NeighborhoodDistance, string ProjUnits) { int tmpIdx; Neighbors = new int[1]; if (NeighborhoodType == IDWNeighborhoodType.Variable) //Taking NeighborhoodCount number of nearest points { if (NeighborhoodDistance == -1) //Then take NeighborhoodCount number of nearest points { Object[] ptIndexObjs = InPointsTree.nearest(InCellPoint, NeighborhoodCount); if (ptIndexObjs.Length == 0) { return(-1); } Neighbors = new int[ptIndexObjs.Length]; for (int i = 0; i < ptIndexObjs.Length; i++) { Neighbors[i] = (int)ptIndexObjs[i]; } } else //Take NeighborhoodCount of nearest points that are a maximum of NeighborhoodDistance away { Object[] ptIndexObjs = InPointsTree.nearest(InCellPoint, NeighborhoodCount); if (ptIndexObjs.Length == 0) { return(-1); } Neighbors = new int[ptIndexObjs.Length]; for (int i = 0; i < ptIndexObjs.Length; i++) { tmpIdx = (int)ptIndexObjs[i]; if (SpatialOperations.Distance(InCellPoint[0], InCellPoint[1], InPoints[tmpIdx][0], InPoints[tmpIdx][1], ProjUnits) <= NeighborhoodDistance) { Neighbors[i] = tmpIdx; } else { Neighbors[i] = -1; } } } } else if (NeighborhoodType == IDWNeighborhoodType.Fixed) //Taking all points in fixed distance { //Something //if (OutNeighbors.Count < NeighborhoodCount) //Test for minimum number of points found //{ // return -1; // //Error //} } else { return(-1); //Error } return(0); }
public static Pdb CopyPdbOccupancyForMergedPsf(Pdb copyto, Pdb copyfrom1, Pdb copyfrom2) { KDTreeDLL.KDTree <Pdb.Atom> kdtree = new KDTreeDLL.KDTree <Pdb.Atom>(3); foreach (var atom in copyfrom1.atoms) { kdtree.insert(atom.coord, atom); } foreach (var atom in copyfrom2.atoms) { kdtree.insert(atom.coord, atom); } Pdb pdb = copyto.Clone(); List <string> nlines = new List <string>(); for (int i = 0; i < pdb.elements.Length; i++) { var elemi = pdb.elements[i]; if ((elemi is Pdb.Atom) == false) { nlines.Add(elemi.line); } else { var atomi = elemi as Pdb.Atom; var atomx = kdtree.nearest(atomi.coord); HDebug.Assert(atomi.coord[0] == atomx.coord[0]); HDebug.Assert(atomi.coord[1] == atomx.coord[1]); HDebug.Assert(atomi.coord[2] == atomx.coord[2]); /// 55 - 60 Real(6.2) occupancy Occupancy. char[] line = atomi.line.ToCharArray(); line[55 - 1] = atomx.line[55 - 1]; line[56 - 1] = atomx.line[56 - 1]; line[57 - 1] = atomx.line[57 - 1]; line[58 - 1] = atomx.line[58 - 1]; line[59 - 1] = atomx.line[59 - 1]; line[60 - 1] = atomx.line[60 - 1]; string nline = line.HToString(); nlines.Add(nline); Pdb.Atom natomi = Pdb.Atom.FromString(nline); pdb.elements[i] = natomi; } } return(pdb); }
private static void CachePoints(string InPointsPath, int InValueFieldIndex, out KDTreeDLL.KDTree PointsTree, out double[][] Points, out double[] PointVals, out string Projection, out string ProjectionUnits, out MapWinGIS.Extents PointsExtents, MapWinGIS.ICallback callback) { int newperc = 0, oldperc = 0; MapWinGIS.Shapefile pointsf = new MapWinGIS.Shapefile(); pointsf.Open(InPointsPath, null); PointsExtents = pointsf.Extents; Projection = pointsf.Projection; if (Projection != null) { ProjectionUnits = Projection.Substring(Projection.IndexOf("units=") + 6); ProjectionUnits = ProjectionUnits.Substring(0, ProjectionUnits.IndexOf("+")).Trim(); } else { double tmpX = pointsf.Extents.xMax; string tmpstr = Math.Floor(tmpX).ToString(); if (tmpstr.Length > 4) { ProjectionUnits = ""; } else { ProjectionUnits = "lat/long"; } } PointsTree = new KDTreeDLL.KDTree(2); MapWinGIS.Point currpt; int ns = pointsf.NumShapes; Points = new double[ns][]; PointVals = new double[ns]; int duplicates = 0; for (int i = 0; i < ns; i++) { Points[i] = new double[2]; newperc = Convert.ToInt32((Convert.ToDouble(i) / Convert.ToDouble(ns)) * 100); if ((newperc > oldperc)) { if (callback != null) { callback.Progress("Status", newperc, "IDW Caching " + i.ToString()); } oldperc = newperc; } currpt = pointsf.get_Shape(i).get_Point(0); Points[i][0] = currpt.x; Points[i][1] = currpt.y; PointVals[i] = double.Parse(pointsf.get_CellValue(InValueFieldIndex, i).ToString()); try { if (PointsTree.search(Points[i]) == null) { PointsTree.insert(Points[i], i); } } catch (KDTreeDLL.KeyDuplicateException) { duplicates++; } } pointsf.Close(); }
public static IEnumerable <Tuple <int, int, double> > EnumHessAnmSpr(IList <Vector> coords, double cutoff, double sprcst) { if (HDebug.Selftest()) { Vector[] _coords = Pdb.FromLines(SelftestData.lines_1L2Y_pdb).atoms.SelectByName("CA").ListCoord().ToArray().HSelectCount(10); HashSet <Tuple <int, int, double> > sprs0 = //EnumHessAnmSpr_obsolete(_coords, 7, 1).HToHashSet(); new HashSet <Tuple <int, int, double> > { new Tuple <int, int, double>(0, 1, 1), new Tuple <int, int, double>(1, 0, 1), new Tuple <int, int, double>(0, 2, 1), new Tuple <int, int, double>(2, 0, 1), new Tuple <int, int, double>(0, 3, 1), new Tuple <int, int, double>(3, 0, 1), new Tuple <int, int, double>(0, 4, 1), new Tuple <int, int, double>(4, 0, 1), new Tuple <int, int, double>(1, 2, 1), new Tuple <int, int, double>(2, 1, 1), new Tuple <int, int, double>(1, 3, 1), new Tuple <int, int, double>(3, 1, 1), new Tuple <int, int, double>(1, 4, 1), new Tuple <int, int, double>(4, 1, 1), new Tuple <int, int, double>(1, 5, 1), new Tuple <int, int, double>(5, 1, 1), new Tuple <int, int, double>(2, 3, 1), new Tuple <int, int, double>(3, 2, 1), new Tuple <int, int, double>(2, 4, 1), new Tuple <int, int, double>(4, 2, 1), new Tuple <int, int, double>(2, 5, 1), new Tuple <int, int, double>(5, 2, 1), new Tuple <int, int, double>(2, 6, 1), new Tuple <int, int, double>(6, 2, 1), new Tuple <int, int, double>(3, 4, 1), new Tuple <int, int, double>(4, 3, 1), new Tuple <int, int, double>(3, 5, 1), new Tuple <int, int, double>(5, 3, 1), new Tuple <int, int, double>(3, 6, 1), new Tuple <int, int, double>(6, 3, 1), new Tuple <int, int, double>(3, 7, 1), new Tuple <int, int, double>(7, 3, 1), new Tuple <int, int, double>(4, 5, 1), new Tuple <int, int, double>(5, 4, 1), new Tuple <int, int, double>(4, 6, 1), new Tuple <int, int, double>(6, 4, 1), new Tuple <int, int, double>(4, 7, 1), new Tuple <int, int, double>(7, 4, 1), new Tuple <int, int, double>(4, 8, 1), new Tuple <int, int, double>(8, 4, 1), new Tuple <int, int, double>(5, 6, 1), new Tuple <int, int, double>(6, 5, 1), new Tuple <int, int, double>(5, 7, 1), new Tuple <int, int, double>(7, 5, 1), new Tuple <int, int, double>(5, 8, 1), new Tuple <int, int, double>(8, 5, 1), new Tuple <int, int, double>(6, 7, 1), new Tuple <int, int, double>(7, 6, 1), new Tuple <int, int, double>(6, 8, 1), new Tuple <int, int, double>(8, 6, 1), new Tuple <int, int, double>(6, 9, 1), new Tuple <int, int, double>(9, 6, 1), new Tuple <int, int, double>(7, 8, 1), new Tuple <int, int, double>(8, 7, 1), new Tuple <int, int, double>(7, 9, 1), new Tuple <int, int, double>(9, 7, 1), new Tuple <int, int, double>(8, 9, 1), new Tuple <int, int, double>(9, 8, 1), }; HashSet <Tuple <int, int, double> > sprs1 = EnumHessAnmSpr(_coords, 7, 1).HToHashSet(); HDebug.Exception(sprs0.Count == sprs1.Count); foreach (var spr in sprs0) { HDebug.Exception(sprs1.Contains(spr)); } } KDTreeDLL.KDTree <object> kdtree = new KDTreeDLL.KDTree <object>(3); for (int i = 0; i < coords.Count; i++) { kdtree.insert(coords[i], i); } int size = coords.Count; double cutoff2 = cutoff * cutoff; int num_springs = 0; for (int c = 0; c < coords.Count; c++) { Vector lowk = coords[c] - (new double[] { cutoff, cutoff, cutoff }); Vector uppk = coords[c] + (new double[] { cutoff, cutoff, cutoff }); foreach (int r in kdtree.range(lowk, uppk)) { if (c >= r) { continue; } double dist2 = (coords[c] - coords[r]).Dist2; if (dist2 < cutoff2) { yield return(new Tuple <int, int, double>(c, r, sprcst)); yield return(new Tuple <int, int, double>(r, c, sprcst)); num_springs += 2; } } } double ratio_springs = ((double)num_springs) / (size * size); }