int main(int argc, const char** argv) { int ret; arg_t args; read_args(argc, argv, &args); printf("args width:%i height:%i rounds:%i hotspots:%s selection:%s\n", args.width_field, args.height_field, args.n_rounds, args.hotspot_filename, argc >= 6 ? args.selection_filename : "empty"); hotspot_vector_t hotspots; hotspot_vector_t coordinates; if (ret = read_hotspots(args.hotspot_filename, &hotspots)) { printf("could not read hotspots from: %s (%d)", args.hotspot_filename, ret); return -1; } field_t field; init_field(args, &field); int current_round = 0; set_hotspots(&field, current_round, &hotspots); while (current_round++ < args.n_rounds) { /*print_field(&field);*/ simulate_round(&field); // double buffering volatile field_value_t * temp = field.old_values; field.old_values = field.new_values; field.new_values = temp; set_hotspots(&field, current_round, &hotspots); } if (argc >= 6) { if (ret = read_coordinates(args.selection_filename, &coordinates)) { printf("could not read coordinates from: %s (%d)", args.selection_filename, ret); return -1; } print_coordinate_values(&field, &coordinates);} else { print_field(&field); } return 0; }
void energy_cal( ) { double *px_coo = NULL ; // double *px_coo_pdb = NULL ; int number_maxcyc = 0; // int i; set_number_maxcyc(number_maxcyc); px_coo = read_coordinates(&number_at); energy_calcul (px_coo, energy, number_at ); printf ("\nTotal energy of molecule = %f \n", energy[0]); printf ("Bond energy of molecule = %f \n", energy[5]); printf ("Angle energy of molecule = %f \n", energy[6]); }
/** * This method does (as its name suggests) the following: * Initialize all the necessary structures so that an energy calculatio is possible * and then launch this calculation. * @param nameOfPDBFile Name of the file for which the energy will be displayed */ void DisplayEnergyForThisPDBFile( char* nameOfPDBFile ) { FILE *fp; char* nameCopy = strdup( nameOfPDBFile ); proteinFileNameNoExt = strtok( nameCopy,"." ); PrintInfo(("\n\n Loading force fields: ")); PrintInfo(("WARNING !! The energy calculation does NOT work with ligands !!! ")); load_force_fields( ); PrintInfo(("\n\n Loading PDB: ")); if ((fp = fopen(nameOfPDBFile, "r")) == NULL) { PrintError(("\n Cannot open the given file ! \n", file_delH)); return; } objProt = AMBER_loadPdb ( fp ); fclose(fp); PrintInfo(("\n\n saving PARM: ")); AMBER_saveParm( (UNIT) objProt); PrintInfo(("\n\n Energy Init: ")); energy_init ( ); px_coo = read_coordinates(&number_at); set_steepest_descent_conjugate_gradient(); set_number_maxcyc( 0 ); energy_calcul (px_coo, energy, number_at ); PARAMET_free(parmet); PrintInfo(("\n\nFile: %s\nEnergy: %f \n", nameOfPDBFile, energy[0])); }
int main(int argc, char *argv[]) { static int ct_AN,h_AN,Gh_AN,i,j,TNO1,TNO2; static int spin,Rn,num0,num1,num2,num3; int II,JJ ; // dummy variables for loop int Anum; // temporary variable int Number_Choo ; // the number of Choosen atom int TNumOrbs,TNumOrbs3; int SPI,SPJ; int optEV ; // variable to be used for option of eigenvector-printing int gcube_on; int *MP ; // array which specify a head position of a full matrix double ***SmallHks, ***O_SmallHks ; double **SmallOLP, **O_SmallOLP ; /* variable & arrays for PART-2; same with that of Cluster_DFT.c */ static int l,n,n2,n1,i1,j0,j1,k1,l1; static int P_min,num_eigen ; static double **ko, *M1; static double **B, ***C, **D; static double sum,sum1,Tsum; // v static double coef[6]; static double **LDOS; read_scfout(argv); read_coordinates(argv); printf("Number of choosen atoms?\n"); scanf("%d",&Number_Choo); if (Number_Choo<=0){ printf("Invalid number\n"); } /************************************************************************* PART-1 : Constructing the selected-full Hamiltonian & Overlap matrix **************************************************************************/ /* allocation of arrays: int Choo_atom[Number_Choo]; int MP[Number_Choo]; double **SmallHks ; double **SmallOLP ; */ Choo_atom = (int*)malloc(sizeof(int)*Number_Choo); MP = (int*)malloc(sizeof(int)*Number_Choo); /* read Choo_atom */ printf("Specify choosen atoms\n"); for (i=0; i<Number_Choo; i++){ scanf("%d",&Choo_atom[i]); } /* make an array MP which specify the starting position of atom II in the martix such as a full but small Hamiltonian */ Anum = 1; for (i=0; i<Number_Choo; i++){ MP[i] = Anum; ct_AN = Choo_atom[i]; Anum = Anum + Total_NumOrbs[ct_AN]; } TNumOrbs = Anum - 1; TNumOrbs3 = TNumOrbs + 3; for (i=0; i<Number_Choo; i++){ ct_AN = Choo_atom[i]; printf("i=%i ct_AN=%i Total_NumOrbs=%i MP=%i\n", i,ct_AN,Total_NumOrbs[ct_AN],MP[i]); } /* allocation of arrays: double **SmallHks ; double **SmallOLP ; */ SmallHks = (double***)malloc(sizeof(double**)*(SpinP_switch+1)); for (spin=0; spin<=SpinP_switch; spin++){ SmallHks[spin] = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ SmallHks[spin][i] = (double*)malloc(sizeof(double)*TNumOrbs3); } } SmallOLP = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ SmallOLP[i] = (double*)malloc(sizeof(double)*TNumOrbs3); } O_SmallHks = (double***)malloc(sizeof(double**)*(SpinP_switch+1)); for (spin=0; spin<=SpinP_switch; spin++){ O_SmallHks[spin] = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ O_SmallHks[spin][i] = (double*)malloc(sizeof(double)*TNumOrbs3); } } O_SmallOLP = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ O_SmallOLP[i] = (double*)malloc(sizeof(double)*TNumOrbs3); } // sorting ? for (spin=0; spin<=SpinP_switch; spin++){ // printf("Kohn-Sham Hamiltonian spin=%i\n",spin); // v for (II=0; II<Number_Choo; II++){ SPI = MP[II]; for (JJ=0; JJ<Number_Choo; JJ++){ SPJ = MP[JJ]; ct_AN = Choo_atom[II] ; TNO1 = Total_NumOrbs[ct_AN]; for (h_AN=0; h_AN<=FNAN[ct_AN]; h_AN++){ Gh_AN = natn[ct_AN][h_AN]; if (Gh_AN == Choo_atom[JJ]){ Rn = ncn[ct_AN][h_AN]; TNO2 = Total_NumOrbs[Gh_AN]; for (i=0; i<TNO1; i++){ for (j=0; j<TNO2; j++){ SmallHks[spin][i+SPI][j+SPJ] = Hks[spin][ct_AN][h_AN][i][j]; SmallOLP[i+SPI][j+SPJ] = OLP[ct_AN][h_AN][i][j]; } } /* printf("glbal index=%i local index=%i (grobal=%i, Rn=%i)\n", ct_AN,h_AN,Gh_AN,Rn); for (i=0; i<TNO1; i++){ for (j=0; j<TNO2; j++){ printf("%10.7f ",Hks[spin][ct_AN][h_AN][i][j]); } printf("\n"); } */ } } } } } /* store original selected Hks and S */ for (spin=0; spin<=SpinP_switch; spin++){ printf("spin=%i Full Hamiltonian matrix of selected atoms\n",spin); for (i=1; i<=TNumOrbs; i++){ for (j=1; j<=TNumOrbs; j++){ printf("%7.3f ",SmallHks[spin][i][j]); // store original information O_SmallHks[spin][i][j] = SmallHks[spin][i][j]; } printf("\n"); } } for (i=1; i<=TNumOrbs; i++){ for (j=1; j<=TNumOrbs; j++){ printf("%7.3f ",SmallOLP[i][j]); O_SmallOLP[i][j] = SmallOLP[i][j]; // store original information } printf("\n"); } for (spin=0; spin<=SpinP_switch; spin++){ printf("spin=%i Full Hamiltonian matrix of selected atoms\n",spin); for (i=1; i<=TNumOrbs; i++){ for (j=1; j<=TNumOrbs; j++){ printf("%7.3f ",SmallHks[spin][i][j]); } printf("\n"); } } printf("Full overlap matrix of selected atoms\n"); for (i=1; i<=TNumOrbs; i++){ for (j=1; j<=TNumOrbs; j++){ printf("%7.3f ",SmallOLP[i][j]); } printf("\n"); } /************************************************************************* PART-2 : Starting the part that diagonalize the selected-full Hamiltonian & Overlap matrix **************************************************************************/ /******************************************* allocation of arrays: double ko[SpinP_switch+1][TNumOrbs3]; double M1[TNumOrbs3]; double B[TNumOrbs3][TNumOrbs3]; ********************************************/ ko = (double**)malloc(sizeof(double*)*(SpinP_switch+1)); for (spin=0; spin<=SpinP_switch; spin++){ ko[spin] = (double*)malloc(sizeof(double)*TNumOrbs3); } M1 = (double*)malloc(sizeof(double)*TNumOrbs3); B = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ B[i] = (double*)malloc(sizeof(double)*TNumOrbs3); } C = (double***)malloc(sizeof(double**)*(SpinP_switch+1)); for (spin=0; spin<=SpinP_switch; spin++){ C[spin] = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ C[spin][i] = (double*)malloc(sizeof(double)*TNumOrbs3); } } D = (double**)malloc(sizeof(double*)*TNumOrbs3); for (i=0; i<TNumOrbs3; i++){ D[i] = (double*)malloc(sizeof(double)*TNumOrbs3); } /******************************************* diagonalize the overlap matrix first SmallOLP -> OLP matrix after call Eigen_lapack SmallOLP -> eigenvectors of OLP matrix ********************************************/ Eigen_lapack(SmallOLP,ko[0],TNumOrbs); for (l=1; l<=TNumOrbs; l++){ M1[l] = 1.0/sqrt(ko[0][l]); } /* for (l=1; l<=TNumOrbs; l++){ printf("%i %15.12f\n",l,M1[l]); } */ /**************************************************** Calculations of eigenvalues for up and down spins ****************************************************/ n = TNumOrbs; for (spin=0; spin<=SpinP_switch; spin++){ for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ sum = 0.0; for (l=1; l<=n; l++){ sum = sum + SmallHks[spin][i1][l]*SmallOLP[l][j1]*M1[j1]; } C[spin][i1][j1] = sum; } } for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ sum = 0.0; for (l=1; l<=n; l++){ sum = sum + M1[i1]*SmallOLP[l][i1]*C[spin][l][j1]; //sum = sum + M1[i1]*SmallOLP[l][i1]*C[spin][l][j1]; } B[i1][j1] = sum; } } for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ D[i1][j1] = B[i1][j1]; } } Eigen_lapack(D,ko[spin],n); /**************************************************** Transformation to the original eigen vectors. NOTE 244P ****************************************************/ for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ C[spin][i1][j1] = 0.0; } } for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ sum = 0.0; for (l=P_min; l<=n; l++){ sum = sum + SmallOLP[i1][l]*M1[l]*D[l][j1]; } C[spin][i1][j1] = sum; } } } for (spin=0; spin<=SpinP_switch; spin++){ printf("\nspin=%i \n",spin); // v for (i=1; i<=TNumOrbs; i++){ printf("%ith eigenvalue of HC=eSC: %15.12f\n",i,ko[spin][i]); } } /* for (spin=0; spin<=SpinP_switch; spin++){ printf("C spin=%i\n",spin); for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ printf("%7.4f ",C[spin][i1][j1]); } printf("\n"); } } */ /**************************************************** Part for Checking 'HC=eSC' ****************************************************/ for (spin=0; spin<=SpinP_switch; spin++){ printf("spin=%i \n", spin); for (j1=1; j1<=n; j1++){ for (i1=1; i1<=n; i1++){ sum = 0.0; sum1= 0.0; for (l=1; l<=n; l++){ sum = sum + O_SmallHks[spin][i1][l]*C[spin][l][j1]; sum1 = sum1 + O_SmallOLP[i1][l]*C[spin][l][j1]; // *ko[spin][j1]; } sum1 = ko[spin][j1] * sum1 ; // ko[spin][i1]?? Tsum = Tsum + fabs(sum-sum1); } printf("Check ko=%i |HC-eSC|=%15.12f\n",j1,Tsum); } } /* for (spin=0; spin<=SpinP_switch; spin++){ printf("spin=%i \n", spin); for (i1=1; i1<=n; i1++){ for (j1=1; j1<=n; j1++){ sum = 0.0; sum1= 0.0; for (l=1; l<=n; l++){ sum = sum + O_SmallHks[spin][i1][l]*C[spin][l][j1]; sum1 = sum1 + O_SmallOLP[i1][l]*C[spin][l][j1]; // *ko[spin][j1]; } sum1 = ko[spin][j1] * sum1 ; // ko[spin][i1]?? printf("l.h.s - r.h.s = %10.7f\n", sum-sum1 ); } } } */ /**************************************************** printing out the eigenvectors ****************************************************/ printf("\nDo you want eigenvectors also? (yes:1 / no:0)"); scanf("%i",&optEV); if (optEV == 1){ num0 = 7; for (spin=0; spin<=SpinP_switch; spin++){ printf("\nspin=%i \n",spin); // v num1 = TNumOrbs/num0; num2 = TNumOrbs%num0; for (i1=0; i1<=num1; i1++){ j0 = i1*num0; for (i=-2; i<=TNumOrbs; i++){ for (j=0; j<=num0; j++){ j1 = j0 + j; if (j1<=TNumOrbs){ if (i==-2){ if (j==0) printf(" "); else printf("%7d ",j1); } else if (i==-1){ if (j==0) printf(" "); else printf("%10.7f ",ko[spin][j1]); } else if (i==0){ if (j==0) printf(" "); else printf(" "); } else { if (j==0) printf("%4d ",i); else printf("%10.7f ",C[spin][i][j1]); } } } printf("\n"); } } } } /* printf("\nDo you want eigenvectors also? (yes:1 / no:0)"); scanf("%i",&optEV); if (optEV == 1){ for (spin=0; spin<=SpinP_switch; spin++){ printf("\nspin=%i \n",spin); // v for (i=1; i<=TNumOrbs; i++){ printf("%ith eigenvector: ",i); printf("{"); for (j=1; j<=TNumOrbs; j++){ printf("%15.12f,",C[spin][i][j]); } printf("}\n"); } } } */ /**************************************************** making Gaussian cube data of MO(d-orbitals) ****************************************************/ printf("\nDo you want Gcube of MO (d-orbitals)? (yes:1 / no:0)"); scanf("%i",&gcube_on); if (gcube_on == 1){ printf("\nWhich eigenstate? (yes:1 / no:0)"); scanf("%i",&num_eigen); printf("\n up or down? (up:0 / down:0)"); scanf("%i",&spin); coef[1] = C[spin][10][num_eigen]; coef[2] = C[spin][11][num_eigen]; coef[3] = C[spin][12][num_eigen]; coef[4] = C[spin][13][num_eigen]; coef[5] = C[spin][14][num_eigen]; Draw_Gcube(coef); } /**************************************************** calculate PDOS of Mn atom ****************************************************/ LDOS = (double**)malloc(sizeof(double*)*30); for (i=0; i<30; i++){ LDOS[i] = (double*)malloc(sizeof(double)*TNumOrbs3); } for (spin=0; spin<=SpinP_switch; spin++){ printf("\nPDOS spin=%i\n",spin); for (i1=10; i1<=14; i1++){ for (i=1; i<=TNumOrbs; i++){ LDOS[i1][i] = 0.0; for (j=1; j<=TNumOrbs; j++){ LDOS[i1][i] += C[spin][i1][i]*C[spin][j][i]*O_SmallOLP[j][i1]; } } } for (i=1; i<=TNumOrbs; i++){ sum = 0.0; for (i1=10; i1<=14; i1++) sum = sum + LDOS[i1][i]; printf("%15.12f %15.12f\n",(ko[spin][i]+0.15)*27.2113845,sum); } } } // the end of 'main'
int main(int argc, char *argv[]) { int i, nbMinimizationCycles = DEFAULT_MINIMIZATION_CYCLES; FILE *fout; if ( argc <= 2 ) { printf("Usage: ambmov -ip <pdbfile for protein> -il <pdbfile for ligand> -o <out pdbfile>\n"); printf(" Optional parameters: \n"); printf(" -n <nb minimization cycles (10)> \n"); printf(" -prep : use \"prep\" intermediary file instead of \"mol2\" \n"); printf(" \n"); printf(" Ambmov can also be used for computing the energy of a given PDB file: \n"); printf(" ambmov -energy <pdbFile> \n\n"); exit(0); } //First parse the parameters. Look for the 3 needed files for (i = 1; i < argc; i += 2) { if (strcmp(argv[i], "-energy") == 0) { //Store the name of the PDBfile in some variable strcpy(ipfilename, argv[i + 1]); //Let the user know what we are doing: PrintInfo(("Received -energy parameter. The program will exit after having displayed the energy !")); //Do the actual thing DisplayEnergyForThisPDBFile( ipfilename ); //And then keep our promise and exit exit(0); } if (strcmp(argv[i], "-ip") == 0) { strcpy(ipfilename, argv[i + 1]); //Remove the hydrogens from the initial PDB removeH (ipfilename); //Compute the name of the pdb without the hydrogens proteinFileNameNoExt = strtok( ipfilename,"." ); strcpy(file_delH,proteinFileNameNoExt); strcat(file_delH,"_delH.pdb"); fPDBwithoutH = fopen(file_delH, "r"); //And verify that the pdb file without hydrogens does exist if ((fPDBwithoutH = fopen(file_delH, "r")) == NULL) { PrintError(("\n Cannot open pdb withot Hs file %s, exit \n", file_delH)); exit(1); } } if (strcmp(argv[i], "-il") == 0) { /* FRAG or FRA in the place of residue label in ligand pdb file and UNIT FRA in prep file to restrain all atoms of ligand in the initial positions */ strcpy(ilfilename, argv[i + 1]); if ((fLigand = fopen(ilfilename, "r")) == NULL) { PrintError(("\n Cannot open ligand pdb file %s, exit \n", ilfilename)); exit(1); } } if (strcmp(argv[i], "-o") == 0) { strcpy(ofilename, argv[i + 1]); } if (strcmp(argv[i], "-n") == 0) { //Try to read the nb of minimization cycles from the given argument if (sscanf( argv[i + 1], "%d", &nbMinimizationCycles) != 1) { //If the reading fails, set the default nb nbMinimizationCycles = DEFAULT_MINIMIZATION_CYCLES; } } if (strcmp(argv[i], "-prep") == 0) { useMol2InsteadOfPrep = 0; } } //for (i=1; ... //Now that we have finished reading all the parameters, // we have also opened the input files (protein and ligand) PrintInfo(("\n\n Loading force fields: ")); load_force_fields( ); PrintInfo(("\n\n Loading PDB: ")); objProt = AMBER_loadPdb ( fPDBwithoutH ); fclose(fPDBwithoutH); PrintInfo(("\n\n finished loading PDB: ")); if (fLigand != NULL ) { load_ligand_pdb (fLigand); fclose(fLigand); ProtLig = AMBER_Combine (objProt, objLig); keepLigandFixedDuringMinimization = 1; //We have a ligand, so keep it fixed PrintInfo(("\n\n saving PARM for the Protein Ligand combination: ")); AMBER_saveParm( (UNIT) ProtLig); } else { PrintInfo(("\n\n saving PARM: ")); AMBER_saveParm( (UNIT) objProt); } PrintInfo(("\n\n Energy _ init: ")); energy_init ( ); PrintInfo(("\n\n Reading coordinates: ")); px_coo = read_coordinates(&number_at); set_steepest_descent_conjugate_gradient(); set_number_maxcyc( nbMinimizationCycles ); energy_calcul (px_coo, energy, number_at ); save_pdb_min ( ); // save total energy in file fout = fopen("totE.ambmovout", "w"); fprintf(fout, "%f",energy[0]); fclose(fout); PARAMET_free(parmet); // printf ("total energy of molecule %f n", energy); PrintInfo(("\n\n Finished ... \n")); return 0; }
PROT load_pdb_binary_no_param(FILE *fp) { PROT prot; memset(&prot, 0, sizeof(PROT)); ATOM atom; int nb_atoms; int nb_residues; int nb_conformers; int i,j,k; int i_atom; //start reading binary PDB file fread(&nb_residues,sizeof(int),1,fp); //printf("%i RESIDUES to read in from binary PDB File. Please wait...\n",nb_residues); int count = 0; int *iatm; int k_RES; int original_index; for(count=0; count<nb_residues; count++) { fread(&nb_conformers,sizeof(int),1,fp);/*read in the number of conformers for this residue*/ //fread(&original_index, sizeof(int),1,fp); //printf("Number of conformers for res#%i:%i\n",count,nb_conformers); if(nb_conformers<=2) { fread(&nb_atoms,sizeof(int),1,fp);/*read in the number of atoms for the backbone conformer*/ //printf("Nb of atoms:%i\n",nb_atoms); for(i=0; i<nb_atoms; i++) { atom = read_full_header(fp); k_RES = check_param(atom,&prot); } if(nb_conformers==2) { fread(&nb_atoms,sizeof(int),1,fp);/*read in the number of atoms for the 1st conformer*/ //printf("Nb of atoms:%i\n",nb_atoms); for(i=0; i<nb_atoms; i++) { atom = read_full_header(fp); k_RES = check_param(atom,&prot); } } } else { fread(&nb_atoms,sizeof(int),1,fp);/*read in the number of atoms for the backbone conformer*/ for(i=0; i<nb_atoms; i++) { atom = read_full_header(fp); k_RES = check_param(atom,&prot); } fread(&nb_atoms,sizeof(int),1,fp);/*read in the number of atoms for the 1st conformer*/ iatm = malloc(sizeof(int)*nb_atoms);//required to keep track of the indices the atoms of the conformer belong to for(i=0; i<nb_atoms; i++) { atom = read_full_header(fp); iatm[i] = iatom(atom.confName, atom.name); k_RES = check_param(atom,&prot); } for(j=2; j<nb_conformers; j++) { read_coordinates(fp,iatm,k_RES,nb_atoms,&prot);/*FIXED to handle different residue locations than 'count', by using the k_RES variable*/ } free(iatm); } //prot.res[k_RES].original_index = original_index; } //FIX SERIAL numbering of all atoms, starting from the 1st atom of the 1st conformer... int serial=1; for(i=0; i<prot.n_res; i++) { for(j=0; j<prot.res[i].n_conf; j++) { for(k=0; k<prot.res[i].conf[j].n_atom; k++) { prot.res[i].conf[j].atom[k].serial = serial; serial++; } } } return prot; }