bool
RegisterContextPOSIXProcessMonitor_arm64::ReadAllRegisterValues(lldb::DataBufferSP &data_sp)
{
    bool success = false;
    data_sp.reset (new lldb_private::DataBufferHeap (REG_CONTEXT_SIZE, 0));
    if (data_sp && ReadGPR () && ReadFPR ())
    {
        uint8_t *dst = data_sp->GetBytes();
        success = dst != 0;

        if (success)
        {
            ::memcpy (dst, &m_gpr_arm64, GetGPRSize());
            dst += GetGPRSize();
            ::memcpy (dst, &m_fpr, sizeof m_fpr);
        }
    }
    return success;
}
Exemple #2
0
int main(int argc, char ** argv)
{
	print_lib_intro_notice(cout);
	print_copyright_notice(cout);
	cout << endl;
	
	// example #2: open a file, run a geometry optimization, and save a file.
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	char infile_name[1048];
	char outfile_name[1048];
	DWORD nFilterIndex;
	if (OpenFileDlg(0, "Ghemical Project File (*.gpr)\0*.gpr\0All files \0*.*\0", 
		infile_name, nFilterIndex) 
		!= S_OK)
	{
		return -1;
	}
	// check that we have got both file names from the command line.
	
	/*if (argc != 3)
	{
		cout << "usage : example2 infile.gpr outfile.gpr" << endl;
		exit(1);
	}
	
	char * infile_name = argv[1];
	char * outfile_name = argv[2];
	*/
	// create a model object, and read in a file.
	
	model * mdl = new model();
	
	cout << "trying to open a file " << infile_name << " ; ";
	
	ifstream ifile;
	ifile.open(infile_name, ios::in);
	
	if (ifile.fail())
	{
		cout << "failed!!!" << endl;
		
		ifile.close();
		delete mdl;
		
		return -1;
	}
	
	cout << "ok!!!" << endl;
	
	ReadGPR(* mdl, ifile, false, false);
	ifile.close();

	printf(
		"mdl->use_periodic_boundary_conditions = %d\n", 
		mdl->use_periodic_boundary_conditions);

	printf(
		"mdl->periodic_box_HALFdim[0] = %f\n", 
		mdl->periodic_box_HALFdim[0]);
	
	printf(
		"mdl->periodic_box_HALFdim[1] = %f\n", 
		mdl->periodic_box_HALFdim[1]);
	
	printf(
		"mdl->periodic_box_HALFdim[2] = %f\n", 
		mdl->periodic_box_HALFdim[2]);
	
	// if everything went fine, then create a computation engine object, initialize it,
	// and create a geometry optimizer object using the computation engine object.
	
	engine * eng = mdl->GetCurrentSetup()->CreateEngineByIDNumber(CURRENT_ENG1_MM);
//	engine * eng = mdl->GetCurrentSetup()->CreateEngineByIDNumber(ENG1_MM_TRIPOS52);
//	engine * eng = mdl->GetCurrentSetup()->CreateEngineByIDNumber(ENG1_MM_DEFAULT);

	// eng_pbc != NULL if we will use a system with periodic boundary conditions...
//	engine_pbc * eng_pbc = dynamic_cast<engine_pbc *>(eng);
#if USE_ENGINE_PBC_TST
	engine_pbc_tst * eng_pbc = dynamic_cast<engine_pbc_tst *>(eng);
#else
	engine_pbc * eng_pbc = dynamic_cast<engine_pbc *>(eng);
#endif /*USE_ENGINE_PBC_TST*/
	
	CopyCRD(mdl, eng, 0);
	CopyLockedCRD(mdl, eng, 0);

	printf("\n%f %f %f %f %f %f\n",
		mdl->maxCRD[0],
		mdl->minCRD[0],
		mdl->maxCRD[1],
		mdl->minCRD[1],
		mdl->maxCRD[2],
		mdl->minCRD[2]);

	mdl->periodic_box_HALFdim[0] = (mdl->maxCRD[0] - mdl->minCRD[0]+0.14) / 2.;
	mdl->periodic_box_HALFdim[1] = (mdl->maxCRD[1] - mdl->minCRD[1]+0.12) / 2.;

	mdl->periodic_box_HALFdim[0] = (mdl->maxCRD[0] - mdl->minCRD[0]) / 2. + 0.14;
	mdl->periodic_box_HALFdim[1] = (mdl->maxCRD[1] - mdl->minCRD[1]) / 2. + 0.12;

	printf(
		"mdl->use_periodic_boundary_conditions = %d\n", 
		mdl->use_periodic_boundary_conditions);

	printf(
		"mdl->periodic_box_HALFdim[0] = %f\n", 
		mdl->periodic_box_HALFdim[0]);
	
	printf(
		"mdl->periodic_box_HALFdim[1] = %f\n", 
		mdl->periodic_box_HALFdim[1]);
	
	printf(
		"mdl->periodic_box_HALFdim[2] = %f\n", 
		mdl->periodic_box_HALFdim[2]);
	
	
	geomopt * opt = new geomopt(eng, 100, 0.025, 10.0);
	
	// then take 100 geometry optimization steps, and print out some data about progess.
	
	for (int n1 = 0;n1 < 100;n1++)
	{
		opt->TakeCGStep(conjugate_gradient::Newton2An);
		eng_pbc->CheckLocations();
		
		cout << "step = " << (n1 + 1) << "   ";
		cout << "energy = " << opt->optval << "   ";
		cout << "step length = " << opt->optstp << endl;
	}
	
	// now copy the optimized coordinates back to the model object, and save the file.
	
	CopyCRD(eng, mdl, 0);
	
	delete opt; opt = NULL;
	delete eng; eng = NULL;
	
	//------------------------------------------------------------------
	TCHAR filter[] =     TEXT("Ghemical Project File (*.gpr)\0*.gpr\0")
						 TEXT("All Files (*.*)\0*.*\0");

	sprintf(outfile_name, "\0");
	if (SaveFileDlg(0, outfile_name, filter, nFilterIndex) == S_OK)
	{
		cout << "now saving file " << outfile_name << endl;
		ofstream ofile;
		ofile.open(outfile_name, ios::out);
		
		WriteGPR_v100(* mdl, ofile);
		ofile.close();
	}
	
	// finally release all allocated memory and leave.
	
	delete mdl; mdl = NULL;
	
	return 0;
}
void Load_traj(int ind1, int ind2, int dim, vector<double> & X)
{
	//print_lib_intro_notice(cout);
	//print_copyright_notice(cout);
	cout << endl;

	// example #2: open a file, run a geometry optimization, and save a file.
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	char infile_name[1048];
	DWORD nFilterIndex;
	if (OpenFileDlg(0, "Ghemical Project File (*.gpr)\0*.gpr\0All files \0*.*\0", 
		infile_name, nFilterIndex) 
		!= S_OK)
	{
		return;
	}


	cout << "trying to open a file " << infile_name << " ; ";

	ifstream ifile;
	ifile.open(infile_name, ios::in);

	if (ifile.fail())
	{
		cout << "failed!!!" << endl;

		ifile.close();
		return;
	}

	cout << "ok!!!" << endl;
#if _USE_WINGHEMICAL_

	//готовим классы для 3D визуализации
	hInst = GetModuleHandle(NULL);

	singleton_cleaner<win_app> app_cleaner;
	win_app * app = win_app::GetInstance();  
	// new win_app() here 
	// -> 	SetNewProject(); 
	// -> new win_project(* win_class_factory::GetInstance());
	// -> new win_class_factory() : graphics_class_factory()
	// 

	// win_project()
	// -> CreateProjectView() -> new win_project_view(prj2) -> LightAdded(); ObjectAdded();

	// win_project()
	// -> AddGraphicsView(NULL, false);

	// project::AddGraphicsView()
	// -> win_class_factory::ProduceGraphicsView() 
	// -> new win_graphics_view(prj2, cam);
	// -> BeginWinGhemical(); view_widget = CreateWinGhemical(this); SendMessage(view_widget, WM_COMMAND, ID_FILE_INITOG2, 0); ConfigureHandler(view_widget);
	app_cleaner.SetInstance(app);

	app->GetWinProject()->SetApp(app);
	//app->work(argc, argv); //
	ReadGPR(* app->GetWinProject(), ifile, false, false);
	ifile.close();

	{
		HANDLE hThread = NULL;
		{
			setup * su = app->GetWinProject()->GetCurrentSetup();
			static jobinfo_MolDyn_tst ji;

			ji.prj = app->GetWinProject();
			ji.md = moldyn_tst_param(su);

			app->GetWinProject()->start_job_MolDyn_tst(& ji);
		}
	}

	StartWinGhemical(NULL);

#else
	model * mdl = new model();
	ReadGPR(* mdl, ifile, false, false);
	ifile.close();
#endif
	char fn[512];
	if (OpenFileDlg(NULL, "Ghemical Trajectory File (*.traj)\0*.traj\0All files \0*.*\0", fn, nFilterIndex) == S_OK)
	{
		cout << "trying to open \"" << fn << "\"." << endl;

		ifstream * trajfile;

		//mdl->OpenTrajectory(filename);
		//{
			i32s traj_num_atoms = mdl->GetAtomCount();
			/*	for (iter_al it1 = GetAtomsBegin();it1 != GetAtomsEnd();it1++)
			{
				if (!((* it1).flags & ATOMFLAG_IS_HIDDEN)) traj_num_atoms++;
			}	
			*/
			
			trajfile = new ifstream(fn, ios::in | ios::binary);
			//trajfile->seekg(8, ios::beg);	// skip the file id...
			char file_id[10];
			trajfile->read((char *) file_id, 8);
			bool extended_trajectory = false;
			if (0 == ::strncmp(file_id, "traj_v11", 8))
				extended_trajectory = true;

			int natoms;
			trajfile->read((char *) & natoms, sizeof(natoms));
			
			if (natoms != traj_num_atoms)
			{
				printf("natoms %d != traj_num_atoms %d\n", natoms, traj_num_atoms);
//				ErrorMessage("The trajectory is incompatible with the current structure/setup!!!");
//				PrintToLog("incompatible file : different number of atoms!\n");
				goto e_close_traj;
			}

			i32s total_traj_frames;			
			trajfile->read((char *) & total_traj_frames, sizeof(total_traj_frames));

			float tstep = 0.0;
			if (extended_trajectory)
				trajfile->read((char *) & tstep, sizeof(tstep));


			
			//char mbuff1[256]; strstream str1(mbuff1, sizeof(mbuff1));
			//str1 << "the trajectory file contains " << total_traj_frames << " frames." << endl << ends;
			//PrintToLog(mbuff1);

			//current_traj_frame = 0;
		//}

		atom * mt_a1;	// measure_tool
		atom * mt_a2;	// measure_tool
		atom * mt_a3;	// measure_tool			

		float ekin;
		float epot;

		X.resize(total_traj_frames);

		//i32s max_frames = app->GetWinProject()->GetTotalFrames();
		for (i32s loop = 0;loop < total_traj_frames; loop++)
		{
			//app->GetWinProject()->SetCurrentFrame(loop);
			//this->ReadFrame();
			//void project::ReadFrame(void)
			//{
				i32s place = GetTrajectoryHeaderSize(extended_trajectory);						// skip the header...
				place += GetTrajectoryFrameSize(extended_trajectory, natoms) * loop;		// get the correct frame...
				//place += GetTrajectoryEnergySize();							// skip epot and ekin...
				
				trajfile->seekg(place, ios::beg);

				trajfile->read((char *) & ekin, sizeof(ekin));
				trajfile->read((char *) & epot, sizeof(epot));

				i32s ind = 0;
				mt_a1 = mt_a2 = mt_a3 = NULL;		



				for (iter_al it1 = mdl->GetAtomsBegin(); it1 != mdl->GetAtomsEnd(); it1++)
				{
				//	if ((* it1).flags & ATOMFLAG_IS_HIDDEN) continue;	// currently all coordinates are written...
					float t1a;
					fGL cdata[3];
					for (i32s t4 = 0;t4 < 3;t4++)
					{
						trajfile->read((char *) & t1a, sizeof(t1a));
						cdata[t4] = t1a;
					}
					if (extended_trajectory)
					{
						for (i32s t4 = 0;t4 < 3;t4++){
							trajfile->read((char *) & t1a, sizeof(t1a));
							//vdata[t4] = t1a;
						}
						for (i32s t4 = 0;t4 < 3;t4++){
							trajfile->read((char *) & t1a, sizeof(t1a));
							//adata[t4] = t1a;
						}
						for (i32s t4 = 0;t4 < 3;t4++){
							trajfile->read((char *) & t1a, sizeof(t1a));
							//fdata[t4] = t1a;
						}
					}
					
					(* it1).SetCRD(0, cdata[0], cdata[1], cdata[2]);

					if (ind == ind1)
					{
						mt_a1 = &(* it1);
					}

					if (ind == ind2)
					{
						mt_a2 = &(* it1);
					}

					/*if (ind == indc)
					{
						mt_a3 = &(* it1);
					}*/


					ind++;
				}
				//this->UpdateAllGraphicsViews();
			//}

				fGL coordinate;

				if (mt_a1 && mt_a2 && dim >=0 && dim < 3)
				{
					const fGL * p1 = mt_a1->GetCRD(0);
					const fGL * p2 = mt_a2->GetCRD(0);
// my measure
//cout  << "el = " << mt_a1->el.GetSymbol() << " " << mt_a1->el.GetAtomicNumber() << " x = " << p1[0] << " y = " << p1[1] << " z = " << p1[2] << endl;
					coordinate = p1[dim]-p2[dim];
				}
				else
					coordinate = 0;

				X[loop] = coordinate;

			//ref->this->UpdateAllGraphicsViews(true);
			//::Sleep(100);
			//void * udata = convert_cset_to_plotting_udata(this, 0);
			//f64 value = coordinate;
			//plot->AddData(loop, value, udata);

			//mt_a1 = mt_a2 = mt_a3 = NULL;
		}
e_close_traj:
		//app->GetWinProject()->CloseTrajectory();
		if (trajfile != NULL)
		{
			trajfile->close();
			delete trajfile;

			trajfile = NULL;
		}
	}
}