@@ -8,7 +8,7 @@ use colored::Colorize;
88use mvmc_io:: { StdFaceParser , DefFileGenerator , DefFileConfig } ;
99use mvmc_core:: config:: { VmcParameters , SRParameters , MonteCarloParameters } ;
1010use mvmc_core:: types:: { SiteCount , ElectronCount , TwoSz , CalcMode , LanczosMode , RandomSeed } ;
11- use std:: path:: PathBuf ;
11+ use std:: path:: { Path , PathBuf } ;
1212
1313/// Standard modeの実行
1414///
@@ -79,6 +79,12 @@ pub fn execute(input_file: PathBuf, output_dir: PathBuf) -> CliResult<()> {
7979
8080 println ! ( "✓ All input files generated successfully" ) ;
8181 println ! ( ) ;
82+
83+ // VMC計算を実行
84+ println ! ( "{}" , "🔬 Running VMC calculation..." . yellow( ) ) ;
85+ run_vmc_calculation ( & vmc_params, & output_dir) ?;
86+ println ! ( "✓ VMC calculation completed successfully" ) ;
87+ println ! ( ) ;
8288 println ! ( "{}" , "═══════════════════════════════════════════" . cyan( ) ) ;
8389 println ! ( "{}" , "✓ Standard mode completed successfully" . green( ) . bold( ) ) ;
8490 println ! ( "{}" , "═══════════════════════════════════════════" . cyan( ) ) ;
@@ -121,4 +127,78 @@ fn convert_stdface_to_vmc_params(stdface_config: &mvmc_io::StdFaceConfig) -> Cli
121127 } ;
122128
123129 Ok ( params)
130+ }
131+
132+ /// VMC計算を実行してzvo_out_001.datを生成
133+ fn run_vmc_calculation ( vmc_params : & VmcParameters , output_dir : & Path ) -> CliResult < ( ) > {
134+ use std:: fs:: File ;
135+ use std:: io:: Write ;
136+ use mvmc_core:: vmc:: VmcEngine ;
137+ use mvmc_physics:: hamiltonian:: HeisenbergHamiltonian ;
138+ use mvmc_physics:: lattice:: ChainLattice ;
139+ use mvmc_physics:: wavefunction:: { CombinedWavefunction , SlaterDeterminant } ;
140+
141+ // ハミルトニアンを作成
142+ let lattice = ChainLattice :: new ( vmc_params. nsite . get ( ) , true )
143+ . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to create lattice: {}" , e) ) ) ?;
144+
145+ let hamiltonian = HeisenbergHamiltonian :: new ( lattice, -0.5 , 0.0 ) // J = -0.5 for Heisenberg chain
146+ . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to create Hamiltonian: {}" , e) ) ) ?;
147+
148+ // 波動関数を作成
149+ let nsite = vmc_params. nsite . get ( ) ;
150+ let ne = vmc_params. ne . get ( ) ;
151+ let slater = SlaterDeterminant :: new_plane_wave ( nsite, ne)
152+ . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to create Slater determinant: {}" , e) ) ) ?;
153+
154+ let wavefunction = CombinedWavefunction :: with_slater ( nsite, ne, slater)
155+ . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to create wavefunction: {}" , e) ) ) ?;
156+
157+ // VMCエンジンを作成
158+ let mut vmc_engine = VmcEngine :: new (
159+ vmc_params. clone ( ) ,
160+ wavefunction,
161+ Box :: new ( hamiltonian) ,
162+ ) . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to create VMC engine: {}" , e) ) ) ?;
163+
164+ // 出力ファイルを作成
165+ let output_file_path = output_dir. join ( "zvo_out_001.dat" ) ;
166+ let mut output_file = File :: create ( & output_file_path)
167+ . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to create output file: {}" , e) ) ) ?;
168+
169+ // VMC計算を実行
170+ let num_iterations = vmc_params. sr_params . iteration_steps ;
171+
172+ println ! ( " Running actual VMC calculation with:" ) ;
173+ println ! ( " - Slater determinant wavefunction" ) ;
174+ println ! ( " - Heisenberg Hamiltonian" ) ;
175+ println ! ( " - Monte Carlo sampling" ) ;
176+ println ! ( " - Energy calculation" ) ;
177+ println ! ( ) ;
178+
179+ for iteration in 0 ..num_iterations {
180+ // VMC計算の1ステップを実行
181+ let result = vmc_engine. run_single_iteration ( )
182+ . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "VMC calculation failed at iteration {}: {}" , iteration, e) ) ) ?;
183+
184+ // 結果をファイルに書き込み
185+ writeln ! (
186+ output_file,
187+ "{:20.15e} {:20.15e} {:20.15e} {:20.15e} {:20.15e} {:20.15e}" ,
188+ result. energy. re,
189+ result. energy. im,
190+ result. variance,
191+ result. sample_count as f64 ,
192+ 0.0 , // その他の統計情報1
193+ 0.0 // その他の統計情報2
194+ ) . map_err ( |e| CliError :: Other ( anyhow:: anyhow!( "Failed to write output: {}" , e) ) ) ?;
195+
196+ // 進捗を表示
197+ if iteration % 10 == 0 || iteration == num_iterations - 1 {
198+ println ! ( " Iteration {}/{}: Energy = {:.6}, Variance = {:.6}" ,
199+ iteration + 1 , num_iterations, result. energy. re, result. variance) ;
200+ }
201+ }
202+
203+ Ok ( ( ) )
124204}
0 commit comments