1 //****************************************************************************** 2 // 3 // Title: Force Field X. 4 // Description: Force Field X - Software for Molecular Biophysics. 5 // Copyright: Copyright (c) Michael J. Schnieders 2001-2024. 6 // 7 // This file is part of Force Field X. 8 // 9 // Force Field X is free software; you can redistribute it and/or modify it 10 // under the terms of the GNU General Public License version 3 as published by 11 // the Free Software Foundation. 12 // 13 // Force Field X is distributed in the hope that it will be useful, but WITHOUT 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 // details. 17 // 18 // You should have received a copy of the GNU General Public License along with 19 // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple 20 // Place, Suite 330, Boston, MA 02111-1307 USA 21 // 22 // Linking this library statically or dynamically with other modules is making a 23 // combined work based on this library. Thus, the terms and conditions of the 24 // GNU General Public License cover the whole combination. 25 // 26 // As a special exception, the copyright holders of this library give you 27 // permission to link this library with independent modules to produce an 28 // executable, regardless of the license terms of these independent modules, and 29 // to copy and distribute the resulting executable under terms of your choice, 30 // provided that you also meet, for each linked independent module, the terms 31 // and conditions of the license of that module. An independent module is a 32 // module which is not derived from or based on this library. If you modify this 33 // library, you may extend this exception to your version of the library, but 34 // you are not obligated to do so. If you do not wish to do so, delete this 35 // exception statement from your version. 36 // 37 //****************************************************************************** 38 package ffx.potential.nonbonded.octree; 39 40 import java.util.ArrayList; 41 42 /** 43 * OctreeCell: Object class for Octree method presented in the Fast Multipole Method (FMM) tutorial 44 * from the Barba Group: https://github.com/barbagroup/FMM_tutorial 45 */ 46 public class OctreeCell { 47 48 /** 49 * Critical (maximum allowed) number of points allowed in any one cell: If a cell already contains 50 * nCritical points, it needs to be split 51 */ 52 private int nCritical; 53 /** Number of leaves in a cell */ 54 private int numLeaves = 0; 55 /** Array of leaf indices */ 56 private ArrayList<Integer> leaves = new ArrayList<>(); 57 /** Integer whose last 8 bits keep track of the empty child cells */ 58 private int nChild = 0; 59 /** Array of child indices, length 8 */ 60 private int[] children = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; 61 /** Parent cell index */ 62 private int parentIndex = 0; 63 64 /** Coordinates for the center of the cell */ 65 private double x = 0.0; 66 67 private double y = 0.0; 68 private double z = 0.0; 69 70 /** Radius of cell */ 71 private double r = 0.0; 72 73 /** Multipole array, length 10 */ 74 private double[] multipole = new double[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 75 76 public OctreeCell(int nCritical) { 77 setnCritical(nCritical); 78 } 79 80 public void addToMultipole(double[] calculatedMultipole) { 81 for (int i = 0; i < 10; i++) { 82 this.multipole[i] += calculatedMultipole[i]; 83 } 84 } 85 86 public int getChildAtIndex(int octant) { 87 return children[octant]; 88 } 89 90 public int getLeavesValueAtIndex(int index) { 91 return this.leaves.get(index); 92 } 93 94 public double[] getMultipole() { 95 return this.multipole; 96 } 97 98 public int getNumLeaves() { 99 return this.numLeaves; 100 } 101 102 public void setNumLeaves(int num) { 103 this.numLeaves = num; 104 } 105 106 public int getParentIndex() { 107 return this.parentIndex; 108 } 109 110 public void setParentIndex(int p) { 111 this.parentIndex = p; 112 } 113 114 /** 115 * Returns cell radius 116 * 117 * @return Returns the cell radius. 118 */ 119 public double getR() { 120 return this.r; 121 } 122 123 /** 124 * Sets cell radius 125 * 126 * @param r The radius. 127 */ 128 public void setR(double r) { 129 this.r = r; 130 } 131 132 /** 133 * Gets x coordinate of center of cell 134 * 135 * @return Returns the x coordinate for center of the cell. 136 */ 137 public double getX() { 138 return this.x; 139 } 140 141 /** 142 * Sets x coordinate of center of cell 143 * 144 * @param x Cell x-coordinate. 145 */ 146 public void setX(double x) { 147 this.x = x; 148 } 149 150 /** 151 * Gets y coordinate of center of cell 152 * 153 * @return Returns the y coordinate for center of the cell. 154 */ 155 public double getY() { 156 return this.y; 157 } 158 159 /** 160 * Sets y coordinate of center of cell 161 * 162 * @param y Cell y-coordinate. 163 */ 164 public void setY(double y) { 165 this.y = y; 166 } 167 168 /** 169 * Gets z coordinate of center of cell 170 * 171 * @return Returns the z coordinate for center of the cell. 172 */ 173 public double getZ() { 174 return this.z; 175 } 176 177 /** 178 * Sets z coordinate of center of cell 179 * 180 * @param z Cell z-coordinate. 181 */ 182 public void setZ(double z) { 183 this.z = z; 184 } 185 186 public int getnChild() { 187 return this.nChild; 188 } 189 190 public void setnChild(int num) { 191 this.nChild = num; 192 } 193 194 public void setChildren(int octant, int c) { 195 this.children[octant] = c; 196 } 197 198 public void setLeaf(int index, int leaf) { 199 this.leaves.set(index, leaf); 200 } 201 202 public void setnCritical(int nCrit) { 203 this.nCritical = nCrit; 204 } 205 }