Esempio n. 1
0
void SaveOptPdb(char szName[])
{
	int i;
	for(i=0; i<n_Phi; i++)	{
		Mol.QueryDihedral(IdxDihSelect[i]);
		Mol.Edit_Dihedral(IdxDihSelect[i], Phi_To_Set_Scan[i]);
	}
	Mol.SavePdb(szName);
}
Esempio n. 2
0
void MM_Fixed_1D_Scan(void)
{
	int i, Phi, Count;

	RestoreCoordinates();
	for(i=0; i<n_Phi; i++)	{
		Mol.QueryDihedral(IdxDihSelect[i]);
		Mol.Edit_Dihedral(IdxDihSelect[i], Phi_To_Set[i]);
	}
	
	Count = 0;
	for(Phi=-180; Phi<=180; Phi+=BIN_SIZE)	{	// 1D scan for this rotamer
		Phi_To_Set[Active_Phi] = Phi*1.0;
		Mol.QueryDihedral(IdxDihSelect[Active_Phi]);
		Mol.Edit_Dihedral(IdxDihSelect[Active_Phi], Phi_To_Set[Active_Phi]);
		E_Phi[Count] = Mol.Cal_E(0);
		Count++;
	}

	return;
}
Esempio n. 3
0
void Output_Gaussian_File(void)
{
	FILE *fOut, *fIn;
	int i, nAtom, IdxScan;
	char szNameGjf[256], szCmd[256], szName_Output[256];

	Determine_QM_Scan_Part();

	nAtom = Mol.nAtom;
	for(IdxScan=0; IdxScan<n_QM_Part; IdxScan++)	{
		Mol.QueryDihedral(IdxDihSelect[Active_Phi]);
		Mol.Edit_Dihedral(IdxDihSelect[Active_Phi], Phi_QM_Start[IdxScan]);

		sprintf(szNameGjf, "qm-scan-%d-%d.gjf", Active_Phi+1, IdxScan+1);
		fOut = fopen(szNameGjf, "w");
		fprintf(fOut, "%s", szQM_Level_1D_Scan_Cmd);
		for(i=0; i<nAtom; i++)	{
//			fprintf(fOut, "%c  %9.5lf %9.5lf %9.5lf\n", Mol.AtomName[i][0], Mol.x[i], Mol.y[i], Mol.z[i]);
			fprintf(fOut, "%s  %9.5lf %9.5lf %9.5lf\n", szElemName[i], Mol.x[i], Mol.y[i], Mol.z[i]);
		}
		fprintf(fOut, "\n");
		
		for(i=0; i<n_Phi; i++)	{
			if(i == Active_Phi)	{
				fprintf(fOut, "%s", szQM_Scan[IdxScan]);
			}
			else	{
				fprintf(fOut, "%d %d %d %d F\n", DihList[i][0]+1, DihList[i][1]+1, DihList[i][2]+1, DihList[i][3]+1);
			}
		}
		fprintf(fOut, "\n");
		fclose(fOut);

		sprintf(szName_Output, "qm-1d-phi-%d-p%d.out", Active_Phi+1, IdxScan+1);
		sprintf(szCmd, "%s < %s > %s", szExe_G09, szNameGjf, szName_Output);


		fIn = fopen(szName_Output, "r");
		if(fIn == NULL)	{
			system(szCmd);
		}
		else	{
			fclose(fIn);
		}

		Extract_Coord_E(szName_Output, Active_Phi, IdxScan);
	}
}
Esempio n. 4
0
void Reorganize_QM_1D_Scan_Data(void)
{
	FILE *fIn, *fOut, *fQMStates;
	int i, j, i_Left, i_Right, Idx_Phi, nScan, nScan_Mapped, ReadItem, nAtom, To_Output[MAX_SCAN];
	char szName_Input[256], szName_Output[256], ErrorMsg[256], szLine[256], *ReadLine, szTmp[256];
	double x_List[MAX_SCAN][MAX_ATOM], y_List[MAX_SCAN][MAX_ATOM], z_List[MAX_SCAN][MAX_ATOM];
	double E_QM[MAX_SCAN], E_MM[MAX_SCAN], Phi[MAX_SCAN], Phi_Mapped[MAX_SCAN], E_QM_Mapped[MAX_SCAN], E_Min, E_Max, Phi_Ini, fTmp=0.0;
	int N_Rotamer_Total=1, nState, DoubleBond;

	RestoreCoordinates();

	nAtom = Mol.nAtom;
	fQMStates = fopen("qm-1d-states.dat", "w");
	for(Idx_Phi=0; Idx_Phi<n_Phi; Idx_Phi++)	{
		sprintf(szName_Input, "tor-1D-idx-%d.dat", Idx_Phi+1);
		sprintf(szName_Output, "new-tor-1D-idx-%d.dat", Idx_Phi+1);

		E_Min = 1.0E100;
		E_Max = -1.0E100;
		Phi_Ini = Mol.QueryDihedral(IdxDihSelect[Idx_Phi]);
		DoubleBond = Is_This_A_Double_Bond(DihList[Idx_Phi][1], DihList[Idx_Phi][2]);

		nScan = 0;
		fIn = fopen(szName_Input, "r");
		if(fIn == NULL)	{
			sprintf(ErrorMsg, "Fail to open file for read: %s\nQuit\n", szName_Input);
			Quit_With_Error_Msg(ErrorMsg);
		}
		while(1)	{
			if(feof(fIn))	{
				break;
			}
			ReadLine = fgets(szLine, 256, fIn);
			if(ReadLine == NULL)	{
				break;
			}
			if(strncmp(szLine, "E_Scan", 6) == 0)	{
				ReadItem = sscanf(szLine, "%s %lf %lf %s %lf", szTmp, &(E_QM[nScan]), &(E_MM[nScan]), szTmp, &(Phi[nScan]));
				if(ReadItem == 5)	{
					fgets(szLine, 256, fIn);
					for(i=0; i<nAtom; i++)	{
						fgets(szLine, 256, fIn);
						ReadItem = sscanf(szLine, "%lf %lf %lf", &(x_List[nScan][i]), &(y_List[nScan][i]), &(z_List[nScan][i]));
						if(ReadItem != 3)	{
							fclose(fIn);
							sprintf(ErrorMsg, "Error in readubg file: %s\nQuit\n", szName_Input);
							Quit_With_Error_Msg(ErrorMsg);
						}
					}
					if(E_QM[nScan] < E_Min)	{
						E_Min = E_QM[nScan];
					}
					if(E_QM[nScan] > E_Max)	{
						E_Max = E_QM[nScan];
					}


					nScan++;
				}
				else	{
					break;
				}
			}
		}
		fclose(fIn);


		for(i=0; i<nScan; i++)	{
			To_Output[i] = 1;
		}

		if( (Phi[0] > 0.0) && (Cal_Phi_Dist(Phi[0], -180.0) < 1.0) )	{	// +180.0 at the first point
			Phi[0] -= 360.0;
		}

		//start	to delete those redundant entries
		for(i=0; i<nScan; i++)	{
			for(j=i+1; j<nScan; j++)	{
				if(Cal_Phi_Dist(Phi[i], Phi[j]) < 1.0)	{	// the same dihedral
					if(Cal_Phi_Dist(Phi[j], -180.0) > 1.0)	{	// only -180, 180 can exist, others will be removed
						To_Output[j] = 0;
					}
				}
			}
		}
		//end	to delete those redundant entries

		//start	to set the correct sign of +180 if it exists as -180
		if(Cal_Phi_Dist(Phi[0], -180.0) < 1.0)	{	// starting with -180
			for(i=nScan-1; i>0; i--)	{
				if(To_Output[i] == 0)	{
					continue;
				}
				
				if( (Phi[i] < 0.0) && (Cal_Phi_Dist(Phi[i], -180.0) < 1.0) )	{
					Phi[i] += 360.0;
//					break;
				}
			}
		}
		//end	to set the correct sign of +180 if it exists as -180

//		fOut = fopen(szName_Output, "w");
		fOut = fopen(szName_Input, "w");	// to overwrite 
		for(j=0; j<nScan; j++)	{
			if(To_Output[j]==0)	{
				continue;
			}
			fprintf(fOut, "E_Scan %.13E %.13E  Phi  %.1lf\n", E_QM[j], E_MM[j], Phi[j]);
			fprintf(fOut, "Coordinate\n");
			for(i=0; i<nAtom; i++)	{
				fprintf(fOut, "%12.6lf %12.6lf %12.6lf\n", x_List[j][i], y_List[j][i], z_List[j][i]);
			}
		}
		
		fclose(fOut);

		//start	to identify QM local minima of each dihedral
		nScan_Mapped = 0;
		for(i=0; i<nScan; i++)	{
			if(To_Output[i])	{
				if(fabs(Phi[i]-180.0) > 3.0)	{	// +180 is excluded
					Phi_Mapped[nScan_Mapped] = Phi[i];
					E_QM_Mapped[nScan_Mapped] = E_QM[i];
					nScan_Mapped++;
				}
			}
		}
		if(nScan_Mapped < 3)	{
			sprintf(ErrorMsg, "nScan_Mapped < 3 for dihedral %d \nQuit\n", Idx_Phi+1);
			Quit_With_Error_Msg(ErrorMsg);
		}
		fprintf(fQMStates, "%3d %3d %3d %3d ", DihList[Idx_Phi][0]+1, DihList[Idx_Phi][1]+1, DihList[Idx_Phi][2]+1, DihList[Idx_Phi][3]+1);
		nState = 0;
		for(i=0; i<nScan_Mapped; i++)	{
			i_Left = (i+nScan_Mapped-1)%nScan_Mapped;
			i_Right = (i+nScan_Mapped+1)%nScan_Mapped;

			if( (DoubleBond) && ( ((E_Max-E_Min)*HARTREE_KCAL) > E_BARRIER_DOUBLE_BOND ) )	{
				fprintf(fQMStates, "  %.0lf", Phi_Ini);
				nState = 1;
				break;
			}

			if( (E_QM_Mapped[i] <= E_QM_Mapped[i_Left]) && (E_QM_Mapped[i] <= E_QM_Mapped[i_Right]) )	{	// a local minimum along QM 1D profile
				fprintf(fQMStates, "  %.0lf", Phi_Mapped[i]);
				nState++;
			}
		}
		fprintf(fQMStates, "\n");
		N_Rotamer_Total *= nState;
		//end	to identify QM local minima of each dihedral
	
	}

	fclose(fQMStates);

	fOut = fopen("n_rotamer.txt", "w");
	fprintf(fOut, "%d", N_Rotamer_Total);
	fclose(fOut);
}
Esempio n. 5
0
void Extract_Coord_E(char szName[], int Idx_Phi, int Idx_Part)
{
	FILE *fIn, *fOut;
	int i, nAtom, ToRead=1, ReadItem, n_Rec=0;
	char szOutput[256], szErrorMsg[256], szLine[256], *ReadLine, szTag[256], ErrorMsg[256];
	double E_QM, E_MM, Phi, Phi_Set, x_Save[MAX_ATOM], y_Save[MAX_ATOM], z_Save[MAX_ATOM];

	nAtom = Mol.nAtom;
	memcpy(x_Save, Mol.x, sizeof(double)*nAtom);
	memcpy(y_Save, Mol.y, sizeof(double)*nAtom);
	memcpy(z_Save, Mol.z, sizeof(double)*nAtom);


	sprintf(szOutput, "tor-1D-idx-%d.dat", Idx_Phi+1);
	fOut = fopen(szOutput, "a+");
	fseek(fOut, 0, SEEK_END);

	fIn = fopen(szName, "r");
	if(fIn == NULL)	{
		sprintf(szErrorMsg, "Fail to open %s\nQuit\n", szName);
		Quit_With_Error_Msg(szErrorMsg);
	}


	while(ToRead)	{
		if(feof(fIn))	{
			break;
		}
		ReadLine = fgets(szLine, 256, fIn);
		if(ReadLine == NULL)	{
			break;
		}
		else	{
//			if(FindString(szLine, " Center     Atomic      Atomic")>=0)	{	// to extract the coordinate
//				Skip_N_Line(fIn, szName, 2);
//			if(FindString(szLine, "     Input orientation:")>=0)	{	// to extract the coordinate
			if(FindString(szLine, " orientation:")>=0)	{	// to extract the coordinate
				Skip_N_Line(fIn, szName, 4);
				for(i=0; i<nAtom; i++)	{
					ReadLine = fgets(szLine, 256, fIn);
					if(ReadLine == NULL)	{
						break;
					}
					ReadItem = sscanf(szLine+31, "%lf %lf %lf", &(Mol.x[i]), &(Mol.y[i]), &(Mol.z[i]));
					if(ReadItem != 3)	{
						ToRead = 0;
						break;
					}
				}
			}
			else if( (FindString(szLine, " SCF Done: ")>=0) && (QM_Level == QM_LEVEL_HF) )	{	// HF
				E_QM = Get_Energy(szLine);
			}
			else if( (FindString(szLine, "EUMP2 =")>=0) && (QM_Level == QM_LEVEL_MP2) )	{
				E_QM = Get_Energy(szLine+27);
			}
			else if(FindString(szLine, " Optimization completed")>=0)	{
				sprintf(szTag, "  D(%d,%d,%d,%d)", DihList[Idx_Phi][0]+1, DihList[Idx_Phi][1]+1, DihList[Idx_Phi][2]+1, DihList[Idx_Phi][3]+1);
				To_Find_Tag(fIn, szName, szTag, szLine);
				ReadItem = sscanf(szLine+28, "%lf", &Phi_Set);	// previous, modredundant
				if(ReadItem != 1)	{
					sprintf(ErrorMsg, "Error in extracting the dihedral.\n%s\nQuit\n", szLine);
					Quit_With_Error_Msg(ErrorMsg);
				}

				Phi = Mol.QueryDihedral(IdxDihSelect[Idx_Phi]);
				E_MM = Mol.Cal_E(0);

				fprintf(fOut, "E_Scan %.13E %.13E  Phi  %.1lf\n", E_QM, E_MM, Phi);
				fprintf(fOut, "Coordinate\n");
				for(i=0; i<nAtom; i++)	{
					fprintf(fOut, "%12.6lf %12.6lf %12.6lf\n", Mol.x[i], Mol.y[i], Mol.z[i]);
				}

				n_Rec++;
			}
		}
	}




	fclose(fOut);
	fclose(fIn);

	memcpy(Mol.x, x_Save, sizeof(double)*nAtom);
	memcpy(Mol.y, y_Save, sizeof(double)*nAtom);
	memcpy(Mol.z, z_Save, sizeof(double)*nAtom);
}
Esempio n. 6
0
int main(int argc, char **argv)
{
	int i;
	FILE *fOut;
	char szName[256];


	fFile_Run_Log = fopen("qm-1d-scan.log", "w");

//	MPI_Init(&argc, &argv);
//	MPI_Comm_rank(MPI_COMM_WORLD, &ProgID);
//	MPI_Comm_size(MPI_COMM_WORLD, &nProc);

	Get_EXE_Path("G09_EXE_PATH", szExe_G09);

	n_Bins = 360/BIN_SIZE+1;


	ForceField.ReadForceField(szForceFiled);
	Mol.ReadPSF(szXpsfFile, 0);
	Get_Netcharge_From_Xpsf();
	Setup_QM_Level();
	ReadElementList();

	Mol.AssignForceFieldParameters(&ForceField);
	Mol.ReadCRD(szCrdFile);
	BackupCoordinates();

	Read_Soft_DihedralList();

	for(Active_Phi=0; Active_Phi<n_Phi; Active_Phi++)	{
		RestoreCoordinates();
		for(i=0; i<n_Phi; i++)	{
			Phi_To_Set[i] = Mol.QueryDihedral(IdxDihSelect[i]);
			Mol.Edit_Dihedral(IdxDihSelect[i], Phi_To_Set[i]);
		}

		MM_Fixed_1D_Scan();
		E_Barrier_Lowest = Get_Barrier(E_Phi, n_Bins, E_Min, Phi_Save);
		E_Min_Save = E_Min;
		E_Min_Org = E_Min + E_RANGE;
		memcpy(E_Scan, E_Phi, sizeof(double)*n_Bins);
		memcpy(Phi_To_Set_Scan, Phi_To_Set, sizeof(double)*n_Phi);
		Phi_To_Set_Scan[Active_Phi] = Phi_Save;

		sprintf(szName, "ini-%d.dat", Active_Phi+1);
		fOut = fopen(szName, "w");
		for(i=0; i<n_Bins; i++)	{
			fprintf(fOut, "%5d %8.5E\n", -180+i*BIN_SIZE, E_Scan[i]-E_Min);
		}
		fclose(fOut);

		sprintf(szName, "ini-%d.pdb", Active_Phi+1);
		SaveOptPdb(szName);

		n_State_List[Active_Phi] = 1;
		Enumerate_Dihedrals(0);
		n_State_List[Active_Phi] = n_State_List_Save[Active_Phi];

		sprintf(szName, "end-%d.dat", Active_Phi+1);
		fOut = fopen(szName, "w");
		for(i=0; i<n_Bins; i++)	{
			fprintf(fOut, "%5d %8.5E\n", -180+i*BIN_SIZE, E_Scan[i]-E_Min_Save);
		}
		fclose(fOut);

		sprintf(szName, "end-%d.pdb", Active_Phi+1);
		SaveOptPdb(szName);

		sprintf(szName, "phi-%d.dat", Active_Phi+1);
		fOut = fopen(szName, "w");
		for(i=0; i<n_Phi; i++)	{
			fprintf(fOut, "%lf\n", Phi_To_Set_Scan[i]);
		}
		fclose(fOut);

	
		Output_Gaussian_File();
	}


	Reorganize_QM_1D_Scan_Data();

	fclose(fFile_Run_Log);

//	MPI_Barrier(MPI_COMM_WORLD);
//	MPI_Finalize();

	return 0;
}
Esempio n. 7
0
int main(int argc, char **argv)
{
	int i;
	FILE *fOut;
	char szName[256], *szEnv;

//	SetEnvironmentVariable(szGAUSS_SCRDIR, "c:\\1");

	fFile_Run_Log = fopen("qm-1d-scan.log", "w");
	
	szEnv = getenv(szGAUSS_SCRDIR);
	if (szEnv == NULL) {
		Quit_With_Error_Msg("Environment variable $GAUSS_SCRDIR is NOT set.\nQuit\n");
	}
	strcpy(szGAUSS_SCRDIR_Base, szEnv);
	


	Get_EXE_Path("G09_EXE_PATH", szExe_G09);

	n_Bins = 360/BIN_SIZE+1;


	ForceField.ReadForceField(szForceFiled);
	Mol.ReadPSF(szXpsfFile, 0);
	Get_Netcharge_From_Xpsf();
	Setup_QM_Level();
	ReadElementList();

	Mol.AssignForceFieldParameters(&ForceField);
	Mol.ReadCRD(szCrdFile);
	BackupCoordinates();

	Read_Soft_DihedralList();

	nJob = nJobDone = 0;

	for(Active_Phi=0; Active_Phi<n_Phi; Active_Phi++)	{
		RestoreCoordinates();
		for(i=0; i<n_Phi; i++)	{
			Phi_To_Set[i] = Mol.QueryDihedral(IdxDihSelect[i]);
			Mol.Edit_Dihedral(IdxDihSelect[i], Phi_To_Set[i]);
		}

		MM_Fixed_1D_Scan();
		E_Barrier_Lowest = Get_Barrier(E_Phi, n_Bins, E_Min, Phi_Save);
		E_Min_Save = E_Min;
		E_Min_Org = E_Min + E_RANGE;
		memcpy(E_Scan, E_Phi, sizeof(double)*n_Bins);
		memcpy(Phi_To_Set_Scan, Phi_To_Set, sizeof(double)*n_Phi);
		Phi_To_Set_Scan[Active_Phi] = Phi_Save;

		sprintf(szName, "ini-%d.dat", Active_Phi+1);
		fOut = fopen(szName, "w");
		for(i=0; i<n_Bins; i++)	{
			fprintf(fOut, "%5d %8.5E\n", -180+i*BIN_SIZE, E_Scan[i]-E_Min);
		}
		fclose(fOut);

		sprintf(szName, "ini-%d.pdb", Active_Phi+1);
		SaveOptPdb(szName);

		n_State_List[Active_Phi] = 1;
		Enumerate_Dihedrals(0);
		n_State_List[Active_Phi] = n_State_List_Save[Active_Phi];

		sprintf(szName, "end-%d.dat", Active_Phi+1);
		fOut = fopen(szName, "w");
		for(i=0; i<n_Bins; i++)	{
			fprintf(fOut, "%5d %8.5E\n", -180+i*BIN_SIZE, E_Scan[i]-E_Min_Save);
		}
		fclose(fOut);

		sprintf(szName, "end-%d.pdb", Active_Phi+1);
		SaveOptPdb(szName);

		sprintf(szName, "phi-%d.dat", Active_Phi+1);
		fOut = fopen(szName, "w");
		for(i=0; i<n_Phi; i++)	{
			fprintf(fOut, "%lf\n", Phi_To_Set_Scan[i]);
		}
		fclose(fOut);

	
		Output_Gaussian_File();
	}

	if(nJob > 0)	{
		RunAllJobs();
		Exatract_All_Info_QM_1D_Scan();
		Reorganize_QM_1D_Scan_Data();
	}

	fclose(fFile_Run_Log);

	return 0;
}