| 1 | /* |
| 2 | mmut/mmut_sasarea.cc: CCP4MG Molecular Graphics Program |
| 3 | Copyright (C) 2001-2008 University of York, CCLRC |
| 4 | |
| 5 | This library is free software: you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public License |
| 7 | version 3, modified in accordance with the provisions of the |
| 8 | license to address the requirements of UK law. |
| 9 | |
| 10 | You should have received a copy of the modified GNU Lesser General |
| 11 | Public License along with this library. If not, copies may be |
| 12 | downloaded from http://www.ccp4.ac.uk/ccp4license.php |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU Lesser General Public License for more details. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | |
| 23 | Calculate Solvent Accessible Surface Area by methods of: |
| 24 | Surface Points |
| 25 | Lee and Richards |
| 26 | Wodak and Janin |
| 27 | |
| 28 | Converted from original CCP4 Fortran code by Stuart McNicholas 2001 |
| 29 | Hacked to CSASArea class structure Liz Potterton 2002 |
| 30 | |
| 31 | */ |
| 32 | |
| 33 | #include <iostream> |
| 34 | #include <string.h> |
| 35 | #include <string> |
| 36 | #include <math.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <sstream> |
| 39 | #include <iomanip> |
| 40 | #include <mman_base.h> |
| 41 | #include <mmut_manager.h> |
| 42 | #include <mman_manager.h> |
| 43 | #include <mmut_sasarea.h> |
| 44 | #include "mginterrupt.h" |
| 45 | |
| 46 | #define MAXPNT 1500 |
| 47 | #define ZSTEP 0.25 |
| 48 | #define ICT 2000 |
| 49 | #define MAXNNBR 1500 // specify array sizes. Ugh! |
| 50 | #define PI 3.141592653589793238462643 |
| 51 | |
| 52 | using namespace std; |
| 53 | |
| 54 | //--------------------------------------------------------------------- |
| 55 | CSASArea::CSASArea( PCMMUTManager molHndin, int selHndin) : |
| 56 | CMMANBase ( molHndin) { |
| 57 | //------------------------------------------------------------------- |
| 58 | InitParams(); |
| 59 | // Set CMMANBase to exclude hydrogen, water and alt confs |
| 60 | int exclude_solvent = 1; |
| 61 | int exclude_hydrogens = 1; |
| 62 | int exclude_alternate = 1; |
| 63 | SetExclusions(exclude_solvent,exclude_hydrogens,exclude_alternate); |
| 64 | SetSelHandle(selHndin); |
| 65 | } |
| 66 | |
| 67 | //--------------------------------------------------------------------- |
| 68 | CSASArea::CSASArea( PCMMUTManager molHndin, int selHndin, |
| 69 | PCMMUTManager molHndin1, int selHndin1) : |
| 70 | CMMANBase ( molHndin,-1,molHndin1,-1) { |
| 71 | //------------------------------------------------------------------- |
| 72 | // INitialise with two sets of atoms - for calculation of |
| 73 | // contact buried SAS |
| 74 | InitParams(); |
| 75 | // Set CMMANBase to exclude hydrogen, water and alt confs |
| 76 | int exclude_solvent = 1; |
| 77 | int exclude_hydrogens = 1; |
| 78 | int exclude_alternate = 1; |
| 79 | SetExclusions(exclude_solvent,exclude_hydrogens,exclude_alternate); |
| 80 | SetSelHandle(0,selHndin,molHndin); |
| 81 | SetSelHandle(1,selHndin1,molHndin1); |
| 82 | } |
| 83 | |
| 84 | //--------------------------------------------------------------------- |
| 85 | CSASArea::CSASArea( PCMMUTManager molHndin) : |
| 86 | CMMANBase ( molHndin) { |
| 87 | //------------------------------------------------------------------- |
| 88 | InitParams(); |
| 89 | // Set CMMANBase to exclude hydrogen, water and alt confs |
| 90 | int exclude_solvent = 1; |
| 91 | int exclude_hydrogens = 1; |
| 92 | int exclude_alternate = 1; |
| 93 | SetExclusions(exclude_solvent,exclude_hydrogens,exclude_alternate); |
| 94 | SetSelHandle(-1); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | //------------------------------------------------------------------- |
| 99 | CSASArea::~CSASArea( ) { |
| 100 | //------------------------------------------------------------------- |
| 101 | } |
| 102 | |
| 103 | //------------------------------------------------------------------- |
| 104 | void CSASArea::InitParams() { |
| 105 | //------------------------------------------------------------------- |
| 106 | //params |
| 107 | HOHrad = 1.4; |
| 108 | brick_margin = 5.0; |
| 109 | point_density = 1.0; |
| 110 | method = LEERICHARDS; |
| 111 | exclude_solvent = 1; |
| 112 | strcpy(keep_altLoc,"A"); |
| 113 | atomUDDHnd = -1; |
| 114 | resUDDHnd = -1; |
| 115 | } |
| 116 | //------------------------------------------------------------------- |
| 117 | void CSASArea::SetParams(int nv, double *value, int niv, int *ivalue) { |
| 118 | //------------------------------------------------------------------- |
| 119 | //params |
| 120 | HOHrad = value[0]; |
| 121 | point_density = value[1]; |
| 122 | brick_margin = value[2]; |
| 123 | exclude_solvent = ivalue[0]; |
| 124 | //cout << " CSASArea::SetParams exclude_solvent " << exclude_solvent << endl; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | //------------------------------------------------------------------ |
| 130 | void CSASArea::SetUDD(int atomUDD,int resUDD) { |
| 131 | //------------------------------------------------------------------ |
| 132 | atomUDDHnd = atomUDD; |
| 133 | resUDDHnd = resUDD; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | //-------------------------------------------------------------------- |
| 139 | int CSASArea::SetMethod ( int meth ) { |
| 140 | //-------------------------------------------------------------------- |
| 141 | if ( meth < 0 || meth > 2 ) return 1; |
| 142 | if ( meth != method ) { |
| 143 | method = meth; |
| 144 | } |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | //------------------------------------------------------------------- |
| 149 | int CSASArea::Calculate_Contact ( void ) { |
| 150 | //------------------------------------------------------------------- |
| 151 | int rv,i,j; |
| 152 | int tmp_selHnd,local_selHnd, nSelAtoms,nSelAtoms1; |
| 153 | mmdb::PPAtom selAtoms,selAtoms1; |
| 154 | rvector radwithhoh; |
| 155 | |
| 156 | if ( !selHnds[0] || ! selHnds[1]) return 1; |
| 157 | |
| 158 | |
| 159 | molHnds[0]->GetSelIndex(selHnds[0],selAtoms,nSelAtoms); |
| 160 | molHnds[1]->GetSelIndex(selHnds[1],selAtoms1,nSelAtoms1); |
| 161 | //cout << " nSelAtoms,nSelAtoms1 " << nSelAtoms << " " << nSelAtoms1 << endl; |
| 162 | if ( nSelAtoms <= 0 || nSelAtoms1 <= 0 ) return 1; |
| 163 | |
| 164 | // Make sure the two selections do not overlap |
| 165 | // TO BE DONE |
| 166 | |
| 167 | // Initialise UDD |
| 168 | int nchains = molHnds[0]->GetNumberOfChains(0); |
| 169 | int nr0,nat0,nat_set; |
| 170 | mmdb::PPResidue resTable; |
| 171 | mmdb::PPAtom atomTable; |
| 172 | for (int ic=0;ic<nchains;ic++) { |
| 173 | resTable = NULL; |
| 174 | molHnds[0]->GetResidueTable(0,ic,resTable,nr0); |
| 175 | if(resUDDHnd>0) { |
| 176 | for (i=0;i<nr0;i++) { |
| 177 | resTable[i]->PutUDData(resUDDHnd,-1.0); |
| 178 | } |
| 179 | } |
| 180 | for (i=0;i<nr0;i++) { |
| 181 | molHnds[0]->GetAtomTable(0,ic,i,atomTable,nat0); |
| 182 | for (j=0;j<nat0;j++) { |
| 183 | atomTable[j]->PutUDData(atomUDDHnd,-1.0); |
| 184 | } |
| 185 | nat_set+= nat0; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // Find the limited number of atoms in selHnd[0] which are close |
| 190 | // to those in selHnd[1] - these are the only atoms which might |
| 191 | // have some buried surface area |
| 192 | tmp_selHnd=molHnds[0]->NewSelection(); |
| 193 | local_selHnd = molHnds[0]->NewSelection(); |
| 194 | // Initially select whole res |
| 195 | molHnds[0]->SelectNeighbours(tmp_selHnd,mmdb::STYPE_RESIDUE,selAtoms1, |
| 196 | nSelAtoms1,0.0,10.0,mmdb::SKEY_NEW); |
| 197 | |
| 198 | |
| 199 | molHnds[0]->Select(local_selHnd,mmdb::STYPE_ATOM,tmp_selHnd,mmdb::SKEY_NEW); |
| 200 | molHnds[0]->Select(local_selHnd,mmdb::STYPE_ATOM,selHnds[0],SKEY_AND); |
| 201 | |
| 202 | // Diagnostic |
| 203 | //molHnds[0]->GetSelIndex(local_selHnd,tmpAtoms,nTmp); |
| 204 | |
| 205 | // Get the atom radii |
| 206 | GetVectorMemory ( radwithhoh, nSelAtoms+nSelAtoms1, 0); |
| 207 | for(i=0;i<nSelAtoms;i++){ |
| 208 | radwithhoh[i] = dynamic_cast<PCMMANManager>(molHnds[0])->GetAtomVDWRadius |
| 209 | (selAtoms[i]) + HOHrad; |
| 210 | if (radwithhoh[i] < 1.0 || radwithhoh[i]>4.0) |
| 211 | cout << "Suspect radius " << radwithhoh[i] << " "; |
| 212 | } |
| 213 | j =nSelAtoms; |
| 214 | for(i=0;i<nSelAtoms1;i++){ |
| 215 | radwithhoh[j] = dynamic_cast<PCMMANManager>(molHnds[1])->GetAtomVDWRadius |
| 216 | (selAtoms1[i]) + HOHrad; |
| 217 | if (radwithhoh[j] < 1.0 || radwithhoh[j]>4.0) |
| 218 | cout << "Suspect radius " << radwithhoh[j] << " "; |
| 219 | j++; |
| 220 | } |
| 221 | |
| 222 | // Calculate the SAS of the first model |
| 223 | rv = LeeAndRichards(radwithhoh,0,0,local_selHnd); |
| 224 | if ( rv>0) return rv; |
| 225 | // Subtract off the SAS of the complex |
| 226 | rv = LeeAndRichards(radwithhoh,0,1,local_selHnd); |
| 227 | if ( rv>0) return rv; |
| 228 | |
| 229 | // Calculate the residue SAS area |
| 230 | if (resUDDHnd>0) ResSASArea(0); |
| 231 | |
| 232 | |
| 233 | // Cleanup |
| 234 | molHnds[0]->DeleteSelection(tmp_selHnd); |
| 235 | FreeVectorMemory ( radwithhoh , 0); |
| 236 | |
| 237 | return rv; |
| 238 | |
| 239 | } |
| 240 | |
| 241 | |
| 242 | //------------------------------------------------------------------- |
| 243 | int CSASArea::Calculate (int imodel,bool separate_models) { |
| 244 | //------------------------------------------------------------------- |
| 245 | int rv = 0; |
| 246 | if ( molHnds[0]->GetNumberOfModels() == 1) |
| 247 | rv = Calculate0(1); |
| 248 | else if (imodel>0 && imodel <= molHnds[0]->GetNumberOfModels()) |
| 249 | rv = Calculate0(imodel); |
| 250 | else if (imodel > molHnds[0]->GetNumberOfModels()) |
| 251 | return 1; |
| 252 | // There is more than 1 model in structure and no specific |
| 253 | // model specified by imodel |
| 254 | else if (separate_models ) { |
| 255 | for (int i = 1; i <= molHnds[0]->GetNumberOfModels(); i++) { |
| 256 | rv = Calculate0(i); |
| 257 | } |
| 258 | } |
| 259 | else |
| 260 | rv = Calculate0(0); |
| 261 | return rv; |
| 262 | } |
| 263 | |
| 264 | //------------------------------------------------------------------- |
| 265 | int CSASArea::Calculate0 (int imodel) { |
| 266 | //------------------------------------------------------------------- |
| 267 | |
| 268 | int RC = 0, i,j,nat; |
| 269 | mmdb::PPAtom selected_atoms; |
| 270 | rvector radwithhoh; |
| 271 | |
| 272 | // Initiallise mmdb udd |
| 273 | int nr0,nat0; |
| 274 | mmdb::PPAtom atomTable; |
| 275 | mmdb::PPResidue resTable; |
| 276 | int im,fm,lm,nchains; |
| 277 | int nat_set = 0; |
| 278 | |
| 279 | if (imodel<1) { |
| 280 | fm=1; |
| 281 | lm = molHnds[0]->GetNumberOfModels(); |
| 282 | } else { |
| 283 | fm = imodel; |
| 284 | lm = imodel; |
| 285 | } |
| 286 | |
| 287 | for (im=fm;im<=lm;im++) { |
| 288 | nchains = molHnds[0]->GetNumberOfChains(im); |
| 289 | |
| 290 | for (int ic=0;ic<nchains;ic++) { |
| 291 | resTable = NULL; |
| 292 | molHnds[0]->GetResidueTable(im,ic,resTable,nr0); |
| 293 | if(resUDDHnd>0) { |
| 294 | for (i=0;i<nr0;i++) { |
| 295 | resTable[i]->PutUDData(resUDDHnd,-1.0); |
| 296 | } |
| 297 | } |
| 298 | for (i=0;i<nr0;i++) { |
| 299 | molHnds[0]->GetAtomTable(im,ic,i,atomTable,nat0); |
| 300 | for (j=0;j<nat0;j++) { |
| 301 | atomTable[j]->PutUDData(atomUDDHnd,-1.0); |
| 302 | } |
| 303 | nat_set+= nat0; |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if (imodel>0) { |
| 309 | GetSelection (selected_atoms, nat,imodel); |
| 310 | } else { |
| 311 | molHnds[0]->GetSelIndex(selHnds[0],selected_atoms, nat); |
| 312 | } |
| 313 | //cout << "Calculate0 imodel " << imodel << " nat " << nat << endl; |
| 314 | |
| 315 | GetVectorMemory ( radwithhoh, nat, 0); |
| 316 | for(i=0;i<nat;i++){ |
| 317 | radwithhoh[i] = dynamic_cast<PCMMANManager>(molHnds[0])->GetAtomVDWRadius |
| 318 | (selected_atoms[i]) + HOHrad; |
| 319 | //cout << " " << radwithhoh[i]; |
| 320 | if (radwithhoh[i] < 1.0 || radwithhoh[i]>4.0) |
| 321 | cout << "Suspect radius " << radwithhoh[i] << " "; |
| 322 | } |
| 323 | |
| 324 | total_area = 0.0; |
| 325 | |
| 326 | // Calculate by the required method |
| 327 | switch ( method ) { |
| 328 | case SURFACEPOINTS: |
| 329 | RC = SurfacePoints(radwithhoh,imodel); |
| 330 | break; |
| 331 | case LEERICHARDS: |
| 332 | RC = LeeAndRichards(radwithhoh,imodel); |
| 333 | break; |
| 334 | case WODAKJANIN: |
| 335 | RC = WodakAndJanin(radwithhoh,imodel); |
| 336 | break; |
| 337 | } |
| 338 | |
| 339 | FreeVectorMemory ( radwithhoh , 0); |
| 340 | |
| 341 | // If method failed then bail out here |
| 342 | if ( RC ) return RC; |
| 343 | |
| 344 | // Calculate the residue SAS area |
| 345 | if (resUDDHnd>0) ResSASArea(imodel); |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | //----------------------------------------------------------------------- |
| 352 | int CSASArea::LeeAndRichards(mmdb::realtype *radwithhoh,int imodel,int imode, |
| 353 | int local_selHnd ){ |
| 354 | //----------------------------------------------------------------------- |
| 355 | |
| 356 | PCBrick brick; |
| 357 | mmdb::realtype total_carea; |
| 358 | int i,j,k,l,nnbr; |
| 359 | mmdb::realtype aarc,xr,yr,zr,rr,rrx2,rrsq; |
| 360 | int x,y,z,ix,iy,iz; |
| 361 | mmdb::realtype sumr, dx, dy, dz, dijsq,rj; |
| 362 | mmdb::realtype *rnnbr; |
| 363 | mmdb::realtype **xyznnbr; |
| 364 | int nzp; |
| 365 | mmdb::realtype zgrid,rsec2r,rsecr,rsec2n,rsecn; |
| 366 | mmdb::realtype *arci, *arcf; |
| 367 | mmdb::realtype arcsum; |
| 368 | int karc; |
| 369 | mmdb::realtype *dsq, *d; |
| 370 | mmdb::realtype *dxn, *dyn; |
| 371 | mmdb::realtype alpha, beta, ti, tf; |
| 372 | mmdb::realtype aarea,carea,aarea0; |
| 373 | int skip_plane; |
| 374 | mmdb::PPAtom selected_atoms, tmp_sel_atoms[2]; |
| 375 | int natoms_sel, tmp_natoms[2]; |
| 376 | |
| 377 | if (imode == 0) { |
| 378 | // Straightforward SAS for one set of atoms |
| 379 | if ( imodel > 0 ) { |
| 380 | GetSelection ( selected_atoms, natoms_sel,imodel); |
| 381 | } else { |
| 382 | molHnds[0]->GetSelIndex(selHnds[0],selected_atoms, natoms_sel); |
| 383 | } |
| 384 | } else { |
| 385 | // Second part of calculating buried area - merge two sets of atoms |
| 386 | molHnds[0]->GetSelIndex(selHnds[0],tmp_sel_atoms[0],tmp_natoms[0]); |
| 387 | molHnds[1]->GetSelIndex(selHnds[1],tmp_sel_atoms[1],tmp_natoms[1]); |
| 388 | //cout << "tmp_natoms " << tmp_natoms[0] << " " << tmp_natoms[1] << endl; |
| 389 | natoms_sel = tmp_natoms[0]+tmp_natoms[1]; |
| 390 | selected_atoms= new mmdb::PAtom[natoms_sel]; |
| 391 | for (i=0;i<tmp_natoms[0];i++) selected_atoms[i] = tmp_sel_atoms[0][i]; |
| 392 | j = tmp_natoms[0]; |
| 393 | for (i=0;i<tmp_natoms[1];i++) { |
| 394 | selected_atoms[j] = tmp_sel_atoms[1][i]; |
| 395 | j++; |
| 396 | } |
| 397 | } |
| 398 | //cout << "LeeAndRichards natoms_sel" << natoms_sel << endl; |
| 399 | |
| 400 | arci = new mmdb::realtype[ICT]; |
| 401 | arcf = new mmdb::realtype[ICT]; |
| 402 | dxn = new mmdb::realtype[MAXNNBR]; |
| 403 | dyn = new mmdb::realtype[MAXNNBR]; |
| 404 | d = new mmdb::realtype[MAXNNBR]; |
| 405 | dsq = new mmdb::realtype[MAXNNBR]; |
| 406 | rnnbr = new mmdb::realtype[MAXNNBR]; |
| 407 | xyznnbr = new mmdb::realtype*[MAXNNBR]; |
| 408 | for(i=0;i<MAXNNBR;i++) |
| 409 | xyznnbr[i] = new mmdb::realtype[3]; |
| 410 | |
| 411 | total_carea = 0.0; |
| 412 | |
| 413 | // cout << "Lee and Richards Calculation\n"; |
| 414 | |
| 415 | molHnds[0]->MakeBricks(selected_atoms,natoms_sel,brick_margin,(HOHrad +2.0)*2.0); |
| 416 | //cout << "natoms_sel " << natoms_sel << endl; |
| 417 | for(i=0;i<natoms_sel;i++){ |
| 418 | if(!selected_atoms[i]->Ter && |
| 419 | (local_selHnd<=0 || selected_atoms[i]->isInSelection(local_selHnd) ) ) { |
| 420 | |
| 421 | if (mginterrupt::GetStatus()>0) { |
| 422 | cout << "SAS interrupted" << endl; |
| 423 | return 1; |
| 424 | } |
| 425 | |
| 426 | aarc = 0; |
| 427 | //cout << "i " << i << selected_atoms[i]->name << endl; |
| 428 | xr = selected_atoms[i]->x; |
| 429 | yr = selected_atoms[i]->y; |
| 430 | zr = selected_atoms[i]->z; |
| 431 | rr = radwithhoh[i]; |
| 432 | rrx2 = rr * 2; |
| 433 | rrsq = rr * rr; |
| 434 | |
| 435 | molHnds[0]->GetBrickCoor(selected_atoms[i],x,y,z); |
| 436 | |
| 437 | nnbr = -1; |
| 438 | for(iz=z-1;iz<z+2;iz++){ |
| 439 | for(iy=y-1;iy<y+2;iy++){ |
| 440 | for(ix=x-1;ix<x+2;ix++){ |
| 441 | brick = NULL; |
| 442 | brick = molHnds[0]->GetBrick(ix,iy,iz); |
| 443 | //cout << "brick " << iz << " " << iy << " " << ix << " " << brick; |
| 444 | //cout << " " << brick->nAtoms << endl; |
| 445 | if ( brick ) { |
| 446 | for(k=0;k<brick->nAtoms;k++){ // Loop over atoms in bin. |
| 447 | j = brick->id[k]; |
| 448 | if(j!=i){ |
| 449 | rj = radwithhoh[j]; |
| 450 | sumr = rr + rj; |
| 451 | dx = selected_atoms[j]->x - xr; |
| 452 | dy = selected_atoms[j]->y - yr; |
| 453 | dz = selected_atoms[j]->z - zr; |
| 454 | // if(1>0){ |
| 455 | if(fabs(dx)<sumr && fabs(dy)<sumr && fabs(dz)<sumr){ |
| 456 | // dijsq = dx*dx + dy*dy; |
| 457 | dijsq = dx*dx + dy*dy + dz*dz; |
| 458 | if(dijsq<(sumr*sumr)){ |
| 459 | nnbr++; |
| 460 | if(nnbr>MAXNNBR){ |
| 461 | cout << "nnbr > MAXNNBR in solvent accessible area calc" << endl; |
| 462 | cout << "Please recompile mmut_sasarea with larger MAXNNBR" << endl; |
| 463 | cout << "and report to CCP4" << endl; |
| 464 | delete [] xyznnbr; |
| 465 | delete [] rnnbr; |
| 466 | delete [] dxn; |
| 467 | delete [] dyn; |
| 468 | delete [] d; |
| 469 | delete [] dsq; |
| 470 | delete [] arci; |
| 471 | delete [] arcf; |
| 472 | |
| 473 | return 1; |
| 474 | } |
| 475 | xyznnbr[nnbr][0] = selected_atoms[j]->x; |
| 476 | xyznnbr[nnbr][1] = selected_atoms[j]->y; |
| 477 | xyznnbr[nnbr][2] = selected_atoms[j]->z; |
| 478 | rnnbr[nnbr] = rj; |
| 479 | dsq[nnbr] = dx*dx + dy*dy; |
| 480 | d[nnbr] = sqrt(dsq[nnbr]); |
| 481 | dxn[nnbr] = dx; |
| 482 | dyn[nnbr] = dy; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | } } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | //cout << "nnbr" << nnbr << endl; |
| 491 | if(nnbr>-1){ |
| 492 | nzp = (int)(rrx2/ZSTEP + 0.5); |
| 493 | zgrid = zr - rr -ZSTEP/2.0; |
| 494 | for(j=0;j<nzp;j++){ |
| 495 | skip_plane = 0; |
| 496 | zgrid = zgrid + ZSTEP; |
| 497 | rsec2r = rrsq - (zgrid-zr)*(zgrid-zr); |
| 498 | if(rsec2r<0) rsec2r = 0.000001; |
| 499 | rsecr = sqrt(rsec2r); |
| 500 | for(k=0;k<ICT;k++){ |
| 501 | arci[k] = 0.0; |
| 502 | arcf[k] = 0.0; |
| 503 | } |
| 504 | karc = -1; |
| 505 | arcsum = 0.0; |
| 506 | for(l=0;l<=nnbr;l++){ |
| 507 | rsec2n = rnnbr[l] * rnnbr[l] - (zgrid - xyznnbr[l][2])*(zgrid - xyznnbr[l][2]); |
| 508 | if(rsec2n>0){ |
| 509 | rsecn = sqrt(rsec2n); |
| 510 | if(d[l]<rsecr+rsecn){ |
| 511 | if(d[l]>fabs(rsecr-rsecn)){ |
| 512 | karc++; |
| 513 | if(karc>ICT){ |
| 514 | cout << "karc > ICT in solvent accessible area calc\n"; |
| 515 | cout << "Please recompile mmut_sasarea with larger ICT and\n"; |
| 516 | cout << "report to CCP4.\n"; |
| 517 | delete [] xyznnbr; |
| 518 | delete [] rnnbr; |
| 519 | delete [] dxn; |
| 520 | delete [] dyn; |
| 521 | delete [] d; |
| 522 | delete [] dsq; |
| 523 | delete [] arci; |
| 524 | delete [] arcf; |
| 525 | return 1; |
| 526 | }else{ |
| 527 | if((dsq[l]+rsec2r-rsec2n)/(2*d[l]*rsecr)>1){ |
| 528 | |
| 529 | |
| 530 | alpha = 0.999; |
| 531 | }else{ |
| 532 | alpha = acos((dsq[l]+rsec2r-rsec2n)/(2*d[l]*rsecr)); |
| 533 | } |
| 534 | beta = atan2(dyn[l],dxn[l]); |
| 535 | if(dyn[l]<0) beta += 2*PI; |
| 536 | ti = beta - alpha; |
| 537 | tf = beta + alpha; |
| 538 | if(ti<0) ti += 2*PI; |
| 539 | if(tf>(2*PI)) tf -= 2*PI; |
| 540 | arci[karc] = ti; |
| 541 | if(tf<ti){ |
| 542 | arcf[karc] = 2*PI; |
| 543 | karc++; |
| 544 | } |
| 545 | arcf[karc] = tf; |
| 546 | } |
| 547 | }else{ |
| 548 | if((rsecr-rsecn)<0){ |
| 549 | // GOTO 170 |
| 550 | skip_plane = 1; |
| 551 | l = nnbr; |
| 552 | } |
| 553 | } // Endif d[l] > fabs(rsecn-rsecr) |
| 554 | } // Endif d[l] < rsecn+rsecr |
| 555 | } // Endif rsec2n > 0 |
| 556 | } // End l loop |
| 557 | if(!skip_plane){ |
| 558 | if(karc>-1){ |
| 559 | SortAB(arci,arcf,karc); |
| 560 | ArcLap(arci,arcf,karc); |
| 561 | arcsum = arci[0]; |
| 562 | if(karc>0){ |
| 563 | for(l=1;l<=karc;l++){ |
| 564 | arcsum += arci[l] - arcf[l-1]; |
| 565 | } |
| 566 | } |
| 567 | arcsum += 2*PI - arcf[karc]; |
| 568 | }else{ |
| 569 | arcsum = 2*PI; |
| 570 | } |
| 571 | } |
| 572 | aarc += arcsum; //170 |
| 573 | } // Loop over NZP |
| 574 | aarea = aarc*rr*ZSTEP; |
| 575 | }else{ |
| 576 | aarea = 4*PI*rr*rr; |
| 577 | } // if nnbr > -1 |
| 578 | carea = (rr - HOHrad) * (rr - HOHrad) * aarea/(rr*rr); |
| 579 | total_area += aarea; |
| 580 | total_carea += carea; |
| 581 | if ( imode == 0 ) { |
| 582 | selected_atoms[i]->PutUDData(atomUDDHnd,aarea); |
| 583 | } else { |
| 584 | selected_atoms[i]->GetUDData(atomUDDHnd,aarea0); |
| 585 | selected_atoms[i]->PutUDData(atomUDDHnd,aarea0-aarea); |
| 586 | } |
| 587 | |
| 588 | } else { |
| 589 | // Atom excluded from local_selHnd but should be given a value |
| 590 | selected_atoms[i]->PutUDData(atomUDDHnd,0.0); |
| 591 | } } // end of atom loop |
| 592 | |
| 593 | |
| 594 | //cout << "Total solvent accessible area: " << total_area << endl; |
| 595 | |
| 596 | delete [] xyznnbr; |
| 597 | |
| 598 | delete [] rnnbr; |
| 599 | delete [] dxn; |
| 600 | delete [] dyn; |
| 601 | delete [] d; |
| 602 | delete [] dsq; |
| 603 | delete [] arci; |
| 604 | delete [] arcf; |
| 605 | if (imode ==1 && selected_atoms) delete[] selected_atoms; |
| 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | //------------------------------------------------------------------------- |
| 611 | int CSASArea::WodakAndJanin(mmdb::realtype *radwithhoh,int imodel){ |
| 612 | //------------------------------------------------------------------------- |
| 613 | |
| 614 | mmdb::PPAtom selected_atoms; |
| 615 | int natoms_sel; |
| 616 | GetSelection ( selected_atoms, natoms_sel,imodel); |
| 617 | // This doesn't seem to want to work |
| 618 | mmdb::realtype b,bpr,ri,rj,dij; |
| 619 | int i,j; |
| 620 | |
| 621 | mmdb::realtype A; |
| 622 | mmdb::realtype B; |
| 623 | mmdb::realtype S; |
| 624 | |
| 625 | for(i=0;i<natoms_sel;i++){ |
| 626 | if(!selected_atoms[i]->Ter) { |
| 627 | S = 4 * PI * radwithhoh[i]*radwithhoh[i]; |
| 628 | A = S; |
| 629 | // cout << "Original S: " << S << endl; |
| 630 | B = 0.0; |
| 631 | for(j=0;j<natoms_sel;j++){ |
| 632 | if(!selected_atoms[j]->Ter) { |
| 633 | if(i!=j){ |
| 634 | ri = dynamic_cast<PCMMANManager>(molHnds[0])->GetAtomVDWRadius(selected_atoms[i]); |
| 635 | rj = dynamic_cast<PCMMANManager>(molHnds[0])->GetAtomVDWRadius(selected_atoms[j]); |
| 636 | |
| 637 | dij = molHnds[0]->BondLength(selected_atoms[i],selected_atoms[j]); |
| 638 | if(dij<(ri + rj + 2*HOHrad)){ |
| 639 | // cout <<"dij, i,j: " << dij << " " << i << ", " << j << endl; |
| 640 | // cout << "i: " << selected_atoms[i]->x << " " << selected_atoms [i]->y << " "<< selected_atoms[i]->z << endl; |
| 641 | // cout << "j: " << selected_atoms[j]->x << " " << selected_atoms[j]->y << " "<< selected_atoms[j]->z << endl; |
| 642 | // Maximum area cut out of i by j. |
| 643 | b = PI * (ri + HOHrad) * (ri + rj + 2*HOHrad - dij)*(1 + (rj - ri)/dij); |
| 644 | // Minimum area assuming hard spheres s = 2*HOHRAD |
| 645 | bpr = PI * (ri + HOHrad) * (ri + rj - dij)*(1 + (rj - 2*HOHrad - ri)/dij); |
| 646 | }else{ |
| 647 | b = 0.0; |
| 648 | bpr = 0.0; |
| 649 | } |
| 650 | |
| 651 | // cout << "b, bpr: " << b << " " << bpr << endl; |
| 652 | // cout << "b - bpr: " << b-bpr << endl; |
| 653 | // cout << "(b - bpr)/S: " << (b-bpr)/S << endl; |
| 654 | |
| 655 | if(bpr<0) bpr = 0; |
| 656 | A *= (1 - (b - bpr)/S); |
| 657 | B += bpr; |
| 658 | // cout << "Current A: " << A << ", Current B: " << B << endl; |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | // cout << "A,B: " << A << B << endl; |
| 663 | if(A<B) { |
| 664 | // cout << "Area on atom " << i << ": 0\n"; |
| 665 | }else{ |
| 666 | cout << "Area on atom " << i << ": " << A - B << endl; |
| 667 | total_area = total_area + A - B; |
| 668 | selected_atoms[i]->PutUDData(atomUDDHnd,A-B); |
| 669 | } |
| 670 | }else{ |
| 671 | selected_atoms[i]->PutUDData(atomUDDHnd,0.0); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | return 0; |
| 676 | |
| 677 | } |
| 678 | |
| 679 | //------------------------------------------------------------------------- |
| 680 | int CSASArea::SurfacePoints(mmdb::realtype *radwithhoh,int imodel) { |
| 681 | //------------------------------------------------------------------------- |
| 682 | |
| 683 | mmdb::PPAtom selected_atoms; |
| 684 | int natoms_sel; |
| 685 | GetSelection ( selected_atoms, natoms_sel,imodel); |
| 686 | PCBrick brick; |
| 687 | |
| 688 | int i,j,k,x,y,z; |
| 689 | int nAtomTypes,atom_type; |
| 690 | mmdb::realtype ri,rj,rk,sarea,points,equat,vert,phi,theta; |
| 691 | mmdb::realtype hor,trunc,rxy,rz; |
| 692 | int nvert,ipt,nhor; |
| 693 | mmdb::realtype ***xyzsph; |
| 694 | int nnbr, ix, iy, iz; |
| 695 | mmdb::realtype sumr, dx, dy, dz, dijsq; |
| 696 | mmdb::realtype **xyznnbr; |
| 697 | mmdb::realtype *rnnbr; |
| 698 | int *nptsph; |
| 699 | int issurface; |
| 700 | int *npoint; |
| 701 | |
| 702 | |
| 703 | npoint = new int[natoms_sel]; |
| 704 | |
| 705 | nAtomTypes = dynamic_cast<PCMMANManager>(molHnds[0])->GetMGSBase()->GetNofLibAtoms(); |
| 706 | //cout << "nAtomTypes" << nAtomTypes << endl; |
| 707 | |
| 708 | xyzsph = new mmdb::realtype**[nAtomTypes]; |
| 709 | for(i=0;i<nAtomTypes;i++){ |
| 710 | xyzsph[i] = new mmdb::realtype*[MAXPNT]; |
| 711 | for(j=0;j<MAXPNT;j++) |
| 712 | xyzsph[i][j] = new mmdb::realtype[3]; |
| 713 | } |
| 714 | |
| 715 | rnnbr = new mmdb::realtype[MAXNNBR]; |
| 716 | xyznnbr = new mmdb::realtype*[MAXNNBR]; |
| 717 | for(i=0;i<MAXNNBR;i++) |
| 718 | xyznnbr[i] = new mmdb::realtype[3]; |
| 719 | |
| 720 | nptsph = new int[nAtomTypes]; |
| 721 | |
| 722 | |
| 723 | // cout << "Calculating Solvent accessible area by surface points\n"; |
| 724 | |
| 725 | // Brick size from areaimol and margin 5. |
| 726 | |
| 727 | molHnds[0]->MakeBricks(selected_atoms,natoms_sel,brick_margin,(HOHrad+2.0)*2.0); |
| 728 | |
| 729 | for(i=0;i<nAtomTypes;i++){ |
| 730 | ri = dynamic_cast<PCMMANManager>(molHnds[0])->GetMGSBase()->libAtom[i].vdwRadius; |
| 731 | //cout << "Atom type rad " << ri << endl; |
| 732 | sarea = 4*PI*ri*ri; |
| 733 | points = sarea*point_density; |
| 734 | equat = sqrt(points*PI); |
| 735 | vert = equat/2.0; |
| 736 | nvert = (int)vert; |
| 737 | |
| 738 | ipt = -1; |
| 739 | trunc = 0.0; |
| 740 | |
| 741 | for(j=0;j<nvert;j++){ |
| 742 | phi = (mmdb::realtype)j*PI/vert; |
| 743 | hor = sin(phi)*equat - trunc; |
| 744 | nhor = (int)hor; |
| 745 | if(j==0) nhor =1; |
| 746 | trunc = (mmdb::realtype)nhor - hor; |
| 747 | rxy = sin(phi)*ri; |
| 748 | rz = cos(phi)*ri; |
| 749 | |
| 750 | for(k=0;k<nhor-1;k++){ |
| 751 | theta = 2.0*PI*(mmdb::realtype)k/(realtype)nhor; |
| 752 | ipt++; |
| 753 | if(ipt>MAXPNT){ |
| 754 | cout << "npt > MAXPNT in solvent accessible area calc\n"; |
| 755 | cout << "Please recompile with larger MAXPNT and\n"; |
| 756 | cout << "report this as ugly code.\n"; |
| 757 | exit(1); |
| 758 | } |
| 759 | xyzsph[i][ipt][0] = cos(theta)*rxy; |
| 760 | xyzsph[i][ipt][1] = sin(theta)*rxy; |
| 761 | xyzsph[i][ipt][2] = rz; |
| 762 | } |
| 763 | } |
| 764 | nptsph[i] = ipt; |
| 765 | } |
| 766 | |
| 767 | for(i=0;i<nAtomTypes;i++) |
| 768 | if(nptsph[i]>0) |
| 769 | // printf("Number of points on atom type %d[%s]: %d\n",i,AtomTypes[i],nptsph[i]); |
| 770 | |
| 771 | for(i=0;i<natoms_sel;i++){ |
| 772 | npoint[i]=0; |
| 773 | atom_type = dynamic_cast<PCMMANManager>(molHnds[0])->GetAtomEnergyType(selected_atoms[i]); |
| 774 | if(!selected_atoms[i]->Ter) { |
| 775 | // Should be an if water, etc condition here. |
| 776 | ri = radwithhoh[i]; |
| 777 | molHnds[0]->GetBrickCoor(selected_atoms[i],x,y,z); |
| 778 | nnbr = -1; |
| 779 | for(iz=z-1;iz<z+2;iz++){ |
| 780 | for(iy=y-1;iy<y+2;iy++){ |
| 781 | for(ix=x-1;ix<x+2;ix++){ |
| 782 | brick = molHnds[0]->GetBrick(ix,iy,iz); |
| 783 | for(k=0;k<brick->nAtoms;k++){ // Loop over atoms in bin. |
| 784 | j = brick->id[k]; |
| 785 | if(j!=i){ |
| 786 | rj = radwithhoh[j]; |
| 787 | sumr = ri + rj; |
| 788 | dx = selected_atoms[i]->x - selected_atoms[j]->x; |
| 789 | dy = selected_atoms[i]->y - selected_atoms[j]->y; |
| 790 | dz = selected_atoms[i]->z - selected_atoms[j]->z; |
| 791 | if(fabs(dx)<sumr && fabs(dy)<sumr && fabs(dz)<sumr){ |
| 792 | dijsq = dx*dx + dy*dy +dz*dz; |
| 793 | if(dijsq<(sumr*sumr)){ |
| 794 | nnbr++; |
| 795 | if(nnbr>MAXNNBR){ |
| 796 | cout << "nnbr > MAXNNBR in solvent accessible area calc\n"; |
| 797 | cout << "Please recompile with larger MAXNNBR and\n"; |
| 798 | cout << "report this as ugly code.\n"; |
| 799 | exit(1); |
| 800 | } |
| 801 | xyznnbr[nnbr][0] = selected_atoms[j]->x; |
| 802 | xyznnbr[nnbr][1] = selected_atoms[j]->y; |
| 803 | xyznnbr[nnbr][2] = selected_atoms[j]->z; |
| 804 | rnnbr[nnbr] = rj; |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | for(j=0;j<nptsph[atom_type];j++){ // Loop over points on sphere. |
| 813 | issurface = 1; |
| 814 | for(k=0;k<=nnbr;k++){ |
| 815 | rk = rnnbr[k]; |
| 816 | dx=0.0; |
| 817 | dy=0.0; |
| 818 | dz=0.0; |
| 819 | dx = selected_atoms[i]->x + xyzsph[atom_type][j][0] - xyznnbr[k][0]; |
| 820 | dy = selected_atoms[i]->y + xyzsph[atom_type][j][1] - xyznnbr[k][1]; |
| 821 | dz = selected_atoms[i]->z + xyzsph[atom_type][j][2] - xyznnbr[k][2]; |
| 822 | if(fabs(dx)<rk && fabs(dy)<rk && fabs(dz)<rk){ |
| 823 | dijsq = dx*dx + dy*dy +dz*dz; |
| 824 | if(dijsq<rk*rk) { |
| 825 | k = nnbr; |
| 826 | issurface = 0; |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | if(issurface) npoint[i]++; |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | delete [] xyznnbr; |
| 836 | |
| 837 | for(i=0;i<nAtomTypes;i++){ |
| 838 | delete [] xyzsph[i]; |
| 839 | } |
| 840 | delete [] xyzsph; |
| 841 | |
| 842 | delete [] rnnbr; |
| 843 | delete [] nptsph; |
| 844 | delete [] xyzsph; |
| 845 | delete [] xyznnbr; |
| 846 | |
| 847 | for(i=0;i<natoms_sel;i++){ |
| 848 | total_area += (mmdb::realtype)npoint[i]; |
| 849 | if(!selected_atoms[i]->Ter) { |
| 850 | selected_atoms[i]->PutUDData(atomUDDHnd,(mmdb::realtype)npoint[i]/point_density); |
| 851 | }else{ |
| 852 | selected_atoms[i]->PutUDData(atomUDDHnd,0.0); |
| 853 | } |
| 854 | } |
| 855 | total_area = total_area/point_density; |
| 856 | delete [] npoint; |
| 857 | |
| 858 | return 0; |
| 859 | |
| 860 | } |
| 861 | |
| 862 | //-------------------------------------------------------------------- |
| 863 | int CSASArea::ResSASArea (int imodel) { |
| 864 | //-------------------------------------------------------------------- |
| 865 | // Sum over all atoms in a residue for residue SAS area |
| 866 | mmdb::realtype sas,tot; |
| 867 | int nr0,nat0, ntot, RC; |
| 868 | mmdb::PPAtom atomTable; |
| 869 | mmdb::PPResidue resTable; |
| 870 | int first_model=1; |
| 871 | int last_model=1; |
| 872 | if (imodel == 0 && molHnds[0]->GetNumberOfModels() > 1) { |
| 873 | first_model = 1; |
| 874 | last_model = molHnds[0]->GetNumberOfModels(); |
| 875 | } |
| 876 | else if (imodel>0) { |
| 877 | first_model = imodel; |
| 878 | last_model = imodel; |
| 879 | } |
| 880 | |
| 881 | for (int im= first_model; im <=last_model;im++) { |
| 882 | //cout << " ResSASArea imodel " << im << endl; |
| 883 | int nchains = molHnds[0]->GetNumberOfChains(im); |
| 884 | for (int ic=0;ic<nchains;ic++) { |
| 885 | molHnds[0]->GetResidueTable(im,ic,resTable,nr0); |
| 886 | for (int i=0;i<nr0;i++) { |
| 887 | molHnds[0]->GetAtomTable(im,ic,i,atomTable,nat0); |
| 888 | tot = 0.0; |
| 889 | ntot = 0; |
| 890 | for (int j=0;j<nat0;j++) { |
| 891 | RC = atomTable[j]->GetUDData(atomUDDHnd,sas); |
| 892 | if (RC == 0 && sas >= 0.0 ) { |
| 893 | tot = tot + sas; |
| 894 | ntot = ntot + 1; |
| 895 | } |
| 896 | } |
| 897 | if ( ntot > 0 ) |
| 898 | resTable[i]->PutUDData(resUDDHnd,tot); |
| 899 | else |
| 900 | resTable[i]->PutUDData(resUDDHnd,-1.0); |
| 901 | //cout << "ResSASArea " << i << " " << tot << endl; |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | //----------------------------------------------------------------------- |
| 909 | std::string CSASArea::Print(int imodel, string selection1, int set_selHnd1, string selection2, int set_selHnd2 ) { |
| 910 | //----------------------------------------------------------------------- |
| 911 | mmdb::PPAtom selected_atoms; |
| 912 | mmdb::PPResidue selected_res; |
| 913 | int RC,i,natoms_sel,nres_sel; |
| 914 | mmdb::realtype sas,total, set_total1,set_total2 ; |
| 915 | std::ostringstream output; |
| 916 | |
| 917 | output.setf(ios::fixed); |
| 918 | output.setf(ios::showpoint); |
| 919 | output.setf(ios::left,ios::adjustfield); |
| 920 | output.precision(2); |
| 921 | int first_model=1; |
| 922 | int last_model=1; |
| 923 | |
| 924 | |
| 925 | if (imodel == 0 && molHnds[0]->GetNumberOfModels() > 1) { |
| 926 | first_model = 1; |
| 927 | last_model = molHnds[0]->GetNumberOfModels(); |
| 928 | } |
| 929 | else if (imodel>0) { |
| 930 | first_model = imodel; |
| 931 | last_model = imodel; |
| 932 | } |
| 933 | |
| 934 | for (int im=first_model;im<=last_model;im++) { |
| 935 | |
| 936 | if (im != 1) output << "For model number " << im << endl; |
| 937 | |
| 938 | |
| 939 | if ( resUDDHnd > 0 ) { |
| 940 | GetSelection ( selected_res, nres_sel,im); |
| 941 | output << "\nSolvent Accessible area by residue\n" << "----------------------------------\n"; |
| 942 | |
| 943 | for (i=1;i<nres_sel;i++){ |
| 944 | RC = selected_res[i]->GetUDData(resUDDHnd,sas); |
| 945 | if ( RC == 0 && sas > 0.001) output << std::setw(15) <<molHnds[0]->AtomLabel_residue1(selected_res[i]) << sas << endl; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | if ( atomUDDHnd > 0 ) { |
| 950 | total = 0.0; |
| 951 | set_total1 = 0.0; |
| 952 | set_total2 = 0.0; |
| 953 | GetSelection ( selected_atoms, natoms_sel,im); |
| 954 | output << "\nSolvent Accessible area by atom\n" |
| 955 | << "-------------------------------" << endl; |
| 956 | |
| 957 | for(i=1;i<natoms_sel;i++) { |
| 958 | RC = selected_atoms[i]->GetUDData(atomUDDHnd,sas); |
| 959 | if ( RC == 0 && sas > 0.001) { |
| 960 | output << std::setw(15) << |
| 961 | molHnds[0]->AtomLabel_atom(selected_atoms[i]) << sas << endl; |
| 962 | total+= sas; |
| 963 | if (set_selHnd1>0 && selected_atoms[i]->isInSelection(set_selHnd1)) set_total1 += sas; |
| 964 | if (set_selHnd2>0 && selected_atoms[i]->isInSelection(set_selHnd2)) set_total2 += sas; |
| 965 | } |
| 966 | } |
| 967 | output << "Total solvent accessible area: " << total << "Angstoem*2" << endl << endl; |
| 968 | if (set_selHnd1>0) output << "Solvent accessible area of " << selection1 << ": " << set_total1 << "Angstoem*2" << endl << endl; |
| 969 | if (set_selHnd2>0) output << "Solvent accessible area of " << selection2 << ": " << set_total2 << "Angstoem*2" << endl << endl; |
| 970 | } |
| 971 | } |
| 972 | return output.str(); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | //---------------------------------------------------------------- |
| 977 | void CSASArea::SortAB(mmdb::realtype *arci, mmdb::realtype *arcf, int &karc) { |
| 978 | //---------------------------------------------------------------- |
| 979 | int i,j,it; |
| 980 | mmdb::realtype aa,bb,temp; |
| 981 | |
| 982 | for(j=0;j<=karc;j++){ |
| 983 | aa = arci[j]; |
| 984 | bb = arcf[j]; |
| 985 | temp = 10.0; |
| 986 | it = j; |
| 987 | for(i=j;i<=karc;i++){ |
| 988 | if(arci[i]<=temp){ |
| 989 | temp = arci[i]; |
| 990 | it = i; |
| 991 | } |
| 992 | } |
| 993 | arci[j] = arci[it]; |
| 994 | arcf[j] = arcf[it]; |
| 995 | arci[it] = aa; |
| 996 | arcf[it] = bb; |
| 997 | } |
| 998 | |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | //-------------------------------------------------------------- |
| 1003 | void CSASArea::ArcLap(mmdb::realtype *arci, mmdb::realtype *arcf, int &karc) { |
| 1004 | //-------------------------------------------------------------- |
| 1005 | mmdb::realtype t; |
| 1006 | int k,l,ks;//,m; |
| 1007 | |
| 1008 | t = arcf[0]; |
| 1009 | ks = 1; |
| 1010 | |
| 1011 | // This might work .... See Fortran |
| 1012 | |
| 1013 | for(k=ks;k<=karc;){ |
| 1014 | if(t>arci[k]){ |
| 1015 | if(arcf[k]>arcf[k-1]) arcf[k-1] = arcf[k]; |
| 1016 | t = arcf[k-1]; |
| 1017 | for(l=k+1;l<=karc;l++){ |
| 1018 | arci[l-1] = arci[l]; |
| 1019 | arcf[l-1] = arcf[l]; |
| 1020 | } |
| 1021 | karc--; |
| 1022 | }else{ |
| 1023 | t = arcf[k]; |
| 1024 | k++; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | } |