#=============================================== # TkVASP #=============================================== package TkVASP; use Crystal::VASP; use TkPlotModule; @ISA = qw(VASP TkPlotModule); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use Utils; use MyTk::GraphFrameArray; use MyTk::BandGraphFrameArray; use MyTk::EnergyLevelGraphFrameArray; use GraphData; #============================================================ # 変数等取得、再定義関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $app) = @_; # my ($module, $app, $canvas) = @_; my $this = {}; bless $this; $this->SetApplication($app); # $this->SetCanvas($canvas); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CreateWidgets { my ($this) = @_; my $mw = $this->mw(); my $canvas = $this->Canvas(); $this->SUPER::CreateWidgets(); # 左枠3列目作成: ファイルの内容を表示するセクションリストボックス # $this->mw()->CreateSectionListBox(); my $LeftFrame = $mw->{LeftFrame1}; my $Frame1 = $LeftFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $Frame1->MyLabel( -text => 'Convolution(DOS):', -takefocus => 0, )->pack(-side => 'left'); $mw->{ConvolutionEntry} = $Frame1->MyEntry( -text => '0.0', -takefocus => 1, )->pack(-side => 'left'); $Frame1->MyLabel( -text => 'eV', -takefocus => 0, )->pack(-side => 'left'); $Frame1 = $LeftFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $Frame1->MyLabel( -text => 'KPoint range:', -takefocus => 0, )->pack(-side => 'left'); $mw->{PlotKPoint0Entry} = $Frame1->MyEntry( -text => '0', -takefocus => 1, )->pack(-side => 'left'); $Frame1->MyLabel( -text => '-', -takefocus => 0, )->pack(-side => 'left'); $mw->{PlotKPoint1Entry} = $Frame1->MyEntry( -text => '0', -takefocus => 1, )->pack(-side => 'left'); $Frame1 = $LeftFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $Frame1->MyLabel( -text => 'EF:', -takefocus => 0, )->pack(-side => 'left'); $mw->{EFEntry} = $Frame1->MyEntry( -text => '0.0', -takefocus => 1, )->pack(-side => 'left'); $Frame1->MyLabel( -text => 'eV', -takefocus => 0, )->pack(-side => 'left'); $Frame1 = $LeftFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $Frame1->MyLabel( -text => 'Scissors:', -takefocus => 0, )->pack(-side => 'left'); $mw->{ScissorsOperatorEntry} = $Frame1->MyEntry( -text => '0.0', -takefocus => 1, )->pack(-side => 'left'); $Frame1->MyLabel( -text => 'eV', -takefocus => 0, )->pack(-side => 'left'); $Frame1 = $LeftFrame->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $mw->{ShowYZeroCheck} = $Frame1->MyCheckbutton( -text => 'Show Y=0', # -variable => $this->{ini}->pVariable("PbPAllowNegativeE2", 0), -onvalue => 1, -offvalue => 0, -indicatoron => 'no', -takefocus => 1, )->pack(-side => 'left'); $mw->{ShowYZeroCheck}->Select(1); $mw->{BandPlotLines} = $Frame1->MyBrowseEntry( -label => "Band plot lines:", -state => "readonly", -takefocus => 1, # -width => 5, -Selections => ['black-red', 'black-gray', 'black-black', 'thin-thick'], #'solid-dot'], -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); # 左枠4列目作成: ファイルの内容を表示するテキストボックス # $this->mw()->CreateFileContentTextBox(); } sub AddWidget { my ($this, $Frame) = @_; return undef unless($Frame); my $mw = $this->mw(); # 左枠3列目作成: ファイルの内容を表示するセクションリストボックス # $this->mw()->CreateSectionListBox(); # 左枠4列目作成: ファイルの内容を表示するテキストボックス # $this->mw()->CreateFileContentTextBox(); return 1; } sub DeleteWidget { my ($this, $Frame) = @_; return undef unless($Frame); return 1; } sub CheckFileType { my ($path) = @_; return VASP::CheckFileType($path); } sub Read { my ($this, $filename, $TargetData) = @_; #print "Read: $filename, $TargetData\n"; my $App = $this->App(); my $mw = $this->mw(); my $s = ''; if($TargetData) { $s = " for $TargetData"; # return $this->Draw(undef, $TargetData); } $mw->WriteStatusBar("Reading $filename$s..."); my $ret = $this->ReadFiles($filename, $TargetData); $mw->WriteStatusBar("Finish reading $filename$s..."); $App->print(" Finish reading $filename$s...\n"); $mw->{PlotKPoint0Entry}->SetText($this->{iKPoint0}); $mw->{PlotKPoint1Entry}->SetText($this->{iKPoint1}); my $Width = $mw->{ConvolutionEntry}->GetText(); print "Width: $Width eV\n"; my $pDataArray = $this->DataArray(); my $pData0 = $pDataArray->GetGraphData(0); my $pData1 = $pDataArray->GetGraphData(1); my $pData2 = $pDataArray->GetGraphData(2); my $IgnoreZeroValue = 0; if($filename =~ /EIGENVAL$/i or $filename =~ /\.csv$/i) { print "Read EIGENVAL\n"; my $EF = $mw->{EFEntry}->GetText(); my $dE = $mw->{ScissorsOperatorEntry}->GetText(); $App->print("Add Scissors Operator [$dE eV]\n"); $this->mw()->WriteStatusBar("Add Scissors Operator [$dE eV]..."); for(my $idx = 0 ; ; $idx++) { my $pX = $pData0->{"x$idx"}; last if(!defined $pX); my $pY1 = $pData0->{"y$idx"}; my $pY2 = $pData1->{"y$idx"}; my $n = @$pX; #print "$idx: p=$pX,$pY1,$pY2,$n\n"; for(my $i = 0 ; $i < $n ; $i++) { if($pY1 and $pY1->[$i] >= $EF) { $pY1->[$i] += $dE; } if($pY2 and $pY2->[$i] >= $EF) { $pY2->[$i] += $dE; } } } $pData0->CalMinMax(); $this->mw()->WriteStatusBar("Add Scissors Operator: Finished."); } elsif($filename =~ /DOSCAR/i and $Width > 0.0) { $this->mw()->WriteStatusBar("Convoluting data..."); for(my $idx = 0 ; ; $idx++) { my $pX = $pData0->{"x$idx"}; last if(!defined $pX); my $nData = @$pX; last if($nData < 2); my $pY = $pData0->{"y$idx"}; last if(!defined $pY); #print "idx=$idx [$nData]\n"; $pData0->{"y$idx"} = Algorism::Convolution($pX, $pY, $Width, "Gaussian", $IgnoreZeroValue); if($this->IsSpinPolarized()) { my $pX2 = $pData2->{"x$idx"}; my $pY2 = $pData2->{"y$idx"}; $pData2->{"y$idx"} = Algorism::Convolution($pX2, $pY2, $Width, "Gaussian", $IgnoreZeroValue); } } $this->mw()->WriteStatusBar("Convoluting data: Finished."); } else { } $this->CreateGraphFrame(); $this->AssignGraphData(); } sub CreateGraphFrame { my ($this, $canvas, $TargetData) = @_; my $mw = $this->mw(); my $App = $this->App(); $canvas = $this->Canvas($canvas); my $w = $canvas->width(); my $h = $canvas->height(); my $pDataArray = $App->TkData(); my $font = $App->{GraphFrameFont}; my @font = split(/,/, $font) if($font); my $FileType = $this->FileType(); print "CreateGraphFrame: FileType [$FileType]\n"; $TargetData = $pDataArray->{TargetData} unless(defined $TargetData); #print "CreateGraphFrame: FileType=$FileType, $canvas, $TargetData\n"; # return if(!defined $TargetData); #print "CreateGraphFrame: FileType=$FileType\n"; if($FileType eq "VASP DOSCAR file") { my $GraphFrameArray = $this->SetGraphFrameArray(new GraphFrameArray($mw)); $GraphFrameArray->SetCanvasSize($w, $h); $GraphFrameArray->AddGraphFrame(); $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{GraphFrameDOS0Position}; #print "Pos0=$FramePosStr0\n"; my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); my $FramePosStr1 = $App->{GraphFrameDOS1Position}; my $XScale1 = $GraphFrame1->GetXScale(0); my $YScale1 = $GraphFrame1->GetYScale(0); $GraphFrame1->SetPositionByStr($FramePosStr1); #print "Pos1=$FramePosStr1\n"; $GraphFrame0->SetXCaption("Energy / eV"); $GraphFrame0->SetYCaption(""); $GraphFrame1->SetXCaption(""); $GraphFrame1->SetYCaption('DOS,Ne'); $XScale0->SetScaleStringVisible(1); $XScale0->SetCaptionVisible(1); $XScale1->SetScaleStringVisible(0); $XScale1->SetCaptionVisible(0); $GraphFrame0->SetViewRange(0, 0, 1, 1); $GraphFrame1->SetViewRange(0, 0, 1, 1); $GraphFrameArray->SetShowScaleDialogCallback(sub { $this->ShowScaleDialog(@_) } ); } elsif($FileType eq "VASP EIGENVAL file" or $FileType eq "CSV Band file") { my $GraphFrameArray = $this->{'GraphFrameArray'} = new BandGraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); #print "GFA1:$GraphFrameArray\n"; $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrame0Position"}; my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); $GraphFrame0->SetXCaption("k"); $GraphFrame0->SetYCaption("Energy / eV"); $XScale0->SetScaleStringVisible(1); $XScale0->SetCaptionVisible(1); $GraphFrame0->SetViewRange(0, 0, 1, 1); } elsif($FileType eq "VASP Output file") { my $GraphFrameArray; if(defined $TargetData and $TargetData eq 'EnergyLevels') { $GraphFrameArray = $this->{'GraphFrameArray'} = new EnergyLevelGraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); } else { $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); } $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrame0Position"}; #print "FramePosStr0 = $FramePosStr0\n"; $GraphFrame0->SetPositionByStr($FramePosStr0); my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); if(defined $TargetData and $TargetData eq 'EnergyConvergence') { $GraphFrame0->SetXCaption("Cycle"); $GraphFrame0->SetYCaption('Energy / eV'); } elsif(defined $TargetData and $TargetData eq 'ForceConvergence') { $GraphFrame0->SetXCaption('Cycle'); $GraphFrame0->SetYCaption('RMS Force / eV/Angstrom'); } elsif(defined $TargetData and $TargetData eq 'EnergyLevels') { $GraphFrame0->SetXCaption("Cycle"); $GraphFrame0->SetYCaption('Energy / eV'); $XScale0->SetScaleStringVisible(0); $XScale0->SetCaptionVisible(0); } $GraphFrame0->SetViewRange(0, 0, 1, 1); } else { my $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); } } sub ShowScaleDialog { my ($this, $GraphFrame, $command, $Title, @a) = @_; #$command: "XScale" "YScale" #最初の4つのundefはViewRangeに現在値を使う #次の2つのundefはPlotTypeに現在値を使う設定 #そのあとの1,0は、X,Y軸のPlotTypeの同期をおこなうかどうか #最後の1は、ScaleDialogでOKを押されたらグラフの再描画を行う #  Y軸のViewRangeは同期するが、PlotTypeの同期は無視する return $GraphFrame->ShowScaleDialog($Title, undef, undef, undef, undef, undef, undef, 1, 0, 1); } sub AssignGraphData { my ($this) = @_; my $mw = $this->mw(); if(!$this->GetGraphFrameArray()) { $this->CreateGraphFrame(); } my $GraphFrameArray = $this->GetGraphFrameArray(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); my $pDataArray = $this->DataArray(); my $FileType = $this->FileType(); my $TargetData = $pDataArray->{TargetData}; return unless($pDataArray); #print "AssignGraphData: FileType [$FileType]\n"; if($FileType eq "VASP DOSCAR file") { my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); if($this->IsSpinPolarized()) { ($GraphFrame0, $GraphFrame1) = ($GraphFrame1, $GraphFrame0); } my $Data0 = $pDataArray->GetGraphData(0); my $Data1 = $pDataArray->GetGraphData(1); my $Data2 = $pDataArray->GetGraphData(2); my $Data3 = $pDataArray->GetGraphData(3); #print "Data: [$Data0] [$Data1] [$Data2] [$Data3]\n"; if($this->IsSpinPolarized()) { # if($Data2) { #print "Spin Polarized\n"; $Data1 = $Data2; } return unless($Data1); my $nData = $Data0->nData(); my $title = $Data0->Title(); if(!$this->IsSpinPolarized()) { for(my $i = 0 ; ; $i++) { my $pX0 = $Data0->GetDataArray("x$i"); last if(not defined $pX0); my $pY0 = $Data0->GetDataArray("y$i"); last if(not defined $pY0); my $nData0 = $GraphFrame0->AddGraphData($pX0, $pY0, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data0->{"x${i}_Name"}, $Data0->{"y${i}_Name"}); if($i == 0) { my $pX1 = $Data1->GetDataArray("x$i"); my $pY1 = $Data1->GetDataArray("y$i"); my $nData1 = $GraphFrame1->AddGraphData($pX1, $pY1, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data1->{"x0_Name"}, $Data1->{"y0_Name"}); } } } else { for(my $i = 0 ; ; $i++) { my $pX0 = $Data0->GetDataArray("x$i"); last if(not defined $pX0); my $pY0 = $Data0->GetDataArray("y$i"); last if(not defined $pY0); my $pX1 = $Data1->GetDataArray("x$i"); last if(not defined $pX1); my $pY1 = $Data1->GetDataArray("y$i"); last if(not defined $pY1); my $nData0 = $GraphFrame0->AddGraphData($pX0, $pY0, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data0->{"x${i}_Name"}, $Data0->{"y${i}_Name"}); my $nData1 = $GraphFrame1->AddGraphData($pX1, $pY1, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data0->{"x${i}_Name"}, $Data1->{"y${i}_Name"}); } } $GraphFrame0->SetYScalePlotType('x'); # $GraphFrame0->SetXCaption("Energy / eV"); # $GraphFrame0->SetYCaption('DOS'); $GraphFrame0->CalMinMax(); $GraphFrame0->AdjustViewRange(0.05, 0.05, 0.05, 0.05); $GraphFrame1->SetYScalePlotType('x'); # $GraphFrame1->SetXCaption("Energy / eV"); # $GraphFrame1->SetYCaption('Ne'); $GraphFrame1->CalMinMax(); $GraphFrame1->AdjustViewRange(0.05, 0.05, 0.05, 0.05); if($GraphFrame1) { $GraphFrame0->AddSynchronousFrame('x', $GraphFrame1); $GraphFrame1->AddSynchronousFrame('x', $GraphFrame0); if($this->IsSpinPolarized()) { $GraphFrame0->AddSynchronousFrame('y', $GraphFrame1); $GraphFrame1->AddSynchronousFrame('y', $GraphFrame0); $GraphFrame1->SetYScalePlotType('-x'); } } } elsif($FileType eq "VASP EIGENVAL file" or $FileType eq "CSV Band file") { print "AssignGraphData: Set for EIGENVAL\n"; my @GraphFrame; my $plotline = $mw->{BandPlotLines}->GetText(); for(my $id = 0 ; ; $id++) { $GraphFrame[$id] = $GraphFrameArray->GetGraphFrame(0); #print "id=$id: GraphFrame=$GraphFrame[$id]\n"; # $GraphFrame[$id] = $GraphFrameArray->GetGraphFrame($id); last unless($GraphFrame[$id]); my $Data = $pDataArray->GetGraphData($id); last if(!defined $Data); my $pX0 = $Data->GetDataArray('x0'); my $linecolor; my $linethickness; if($id == 0) { $linecolor = 'black'; $linethickness = 1; } elsif($id == 1) { $linethickness = 1; if($plotline =~ /-gray/) { $linecolor = 'gray'; } elsif($plotline =~ /-black/) { $linecolor = 'black'; } if($plotline =~ /-thick/) { $linecolor = 'black'; $linethickness = 2; } else { $linecolor = 'red'; } } #print "id=$id c=$linecolor\n"; for(my $i = 0 ; ; $i++) { my $pY = $Data->GetDataArray("y$i"); last unless($pY); my $nData = $GraphFrame[$id]->AddGraphData($pX0, $pY, $linethickness, $linecolor, "", 6, "red", 0, "red", "XAutoSkip", $Data->{"x0_Name"}, $Data->{"y${i}_Name"}); my $data = $GraphFrame[$id]->GetPlotData($nData-1); } $GraphFrame[$id]->CalMinMax(); $GraphFrame[$id]->AdjustViewRange(0.0, 0.0, 0.05, 0.05); # $GraphFrame[$id]->AdjustViewRange(0.05, 0.05, 0.05, 0.05); $GraphFrame[$id]->{'pBandBoundaryDistances'} = $pDataArray->{'pBandBoundaryDistances'}; $GraphFrame[$id]->{'pBandBoundaryPositions'} = $pDataArray->{'pBandBoundaryPositions'}; $GraphFrame[$id]->{'pKPointName'} = $pDataArray->{'pKPointNameArray'}; } if($GraphFrame[1]) { $GraphFrame[0]->AddSynchronousFrame('x', $GraphFrame[1]); $GraphFrame[0]->AddSynchronousFrame('y', $GraphFrame[1]); $GraphFrame[1]->AddSynchronousFrame('x', $GraphFrame[0]); $GraphFrame[1]->AddSynchronousFrame('y', $GraphFrame[0]); } } elsif($FileType eq "VASP Output file") { my $Data = $pDataArray->GetGraphData(0); return unless($Data); my $nData = $Data->nData(); my $title = $Data->Title(); my $pX0 = $Data->GetDataArray('x0'); for(my $i = 0 ; ; $i++) { my $pY = $Data->GetDataArray("y$i"); last unless($pY); if($TargetData eq 'EnergyLevels') { my $nData = $GraphFrame0->AddGraphData($pX0, $pY, 0, "auto", "hbar", 300, "red", 0, "red", "XAutoSkip", $Data->{"x0_Name"}, $Data->{"y${i}_Name"}); my $pData = $GraphFrame0->GetPlotData($nData-1); $pData->SetVisible(0); $GraphFrame0->{'BandNo'} = $pData->{'BandNo'}; $GraphFrame0->{'x0'} = $pData->{'x0'}; $GraphFrame0->{'x0_Name'} = $pData->{'x0_Name'}; $GraphFrame0->{'y0'} = $pData->{'y0'}; $GraphFrame0->{'pGraphData'} = $this->DataArray()->GetGraphData(0); } else { my $nData = $GraphFrame0->AddGraphData($pX0, $pY, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data->{"x0_Name"}, $Data->{"y${i}_Name"}); } } if($TargetData =~ /EnergyConvergence/i) { $GraphFrame0->SetYScalePlotType('x'); $GraphFrame0->SetXCaption("Cycle"); $GraphFrame0->SetYCaption('Energy / eV'); } elsif($TargetData =~ /ForceConvergence/i) { $GraphFrame0->SetYScalePlotType('x'); $GraphFrame0->SetXCaption("Cycle"); $GraphFrame0->SetYCaption('Force / eV/Angstrom'); } else { $GraphFrame0->SetXCaption("Cycle"); $GraphFrame0->SetYCaption('Energy / eV'); } $GraphFrame0->CalMinMax(); $GraphFrame0->AdjustViewRange(0.05, 0.05, 0.05, 0.05); } $GraphFrame0->SetY0LineVisible(1) if($GraphFrame0); $GraphFrame1->SetY0LineVisible(1) if($GraphFrame1); #print "ShowY0: ", $mw->{ShowYZeroCheck}->Status(), "\n"; if(!$mw->{ShowYZeroCheck}->Status()) { if($GraphFrame0) { $GraphFrame0->SetY0LineVisible(0); } if($GraphFrame1) { $GraphFrame1->SetY0LineVisible(0); } } $this->AdjustViewRange(); } sub AdjustViewRange { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $FileType = $this->FileType(); if($FileType eq "VASP DOSCAR file") { } elsif($FileType eq "VASP EIGENVAL file" or $FileType eq "CSV Band file") { # my $GraphFrameArray = $this->GetGraphFrameArray(); # my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); # my ($xmin, $xmax) = $GraphFrame0->GetViewXRange(); # my ($ymin, $ymax) = $GraphFrame0->GetViewYRange(); # for(my $id = 1 ; ; $id++) { # my $GraphFrame = $GraphFrameArray->GetGraphFrame($id); # last unless($GraphFrame); # $GraphFrame->SetViewRange($xmin, $ymin, $xmax, $ymax); # } } } sub Draw { my ($this, $canvas, $TargetData) = @_; #print "Draw\n"; if(!$this->GetGraphFrameArray()) { return; # $this->CreateGraphFrame(); # $this->AssignGraphData(); } my $mw; my $GraphFrameArray; my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); #print "TargetData=$TargetData\n"; #TargetDataが指定されていたらOUTCARを読み込みなおす if($TargetData) { $this->DataArray()->{TargetData} = $TargetData; #print "Read for $TargetData\n"; $canvas->ClearAll(); $this->mw()->RefleshCanvas(); #変数の再取得 $mw = $this->mw(); $canvas = $this->Canvas(); $this->ReadFiles($this->FileName(), $TargetData); $this->CreateGraphFrame($canvas, $TargetData); $this->AssignGraphData(); $this->SetFileInfo($this->{'SectionListbox'}, $this->{'FileContentText'}); } $canvas = $this->Canvas($canvas); $mw = $this->mw(); $GraphFrameArray = $this->GetGraphFrameArray(); #print "Draw: GraphFrameArray=$GraphFrameArray\n"; if($font) { $canvas->SetFont(\@font); $GraphFrameArray->SetFont(\@font); } my $w = $canvas->width(); my $h = $canvas->height(); $GraphFrameArray->SetCanvasSize($w, $h); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my @GraphFrame = @$pGraphFrame; my $pDataArray = $this->TkPlotModule::DataArray(); my $pData = $pDataArray->GetGraphData(0); $TargetData = $pDataArray->{TargetData} unless($TargetData); my $FileType = $this->FileType(); #print "Target: TargetData [$TargetData], FileType [$FileType]\n"; #DOSCAR if($FileType eq "VASP DOSCAR file") { $mw->RefleshCanvas(); $mw->WriteStatusBar("Drawing DOS..."); $mw->Balloon()->detach($canvas); $GraphFrameArray->Draw($canvas); $this->mw()->WriteStatusBar("Finish Drawing DOS."); return; } #EIGENVAL if($FileType eq "VASP EIGENVAL file") { print("Drawing VASP Band\n"); $mw->RefleshCanvas(); $mw->WriteStatusBar("Drawing VASP Band..."); $mw->Balloon()->detach($canvas); $GraphFrameArray->Draw($canvas); $this->mw()->WriteStatusBar("Finish Drawing VASP Band."); return; } if($FileType eq "CSV Band file") { print("Drawing CSV Band\n"); $mw->RefleshCanvas(); $mw->WriteStatusBar("Drawing VASP Band..."); $mw->Balloon()->detach($canvas); $GraphFrameArray->Draw($canvas); $this->mw()->WriteStatusBar("Finish Drawing VASP Band."); return; } #OUTCAR $this->mw()->Balloon()->detach($canvas); #エネルギー準位をプロット if($TargetData =~ /EnergyLevels/i) { $this->mw()->WriteStatusBar("Drawing Energy Levels..."); return unless($TargetData eq 'EnergyLevels'); $GraphFrameArray->Draw($canvas); # $this->mw()->Balloon()->attach($canvas, # -balloonposition => 'mouse', -msg => \%TagHash); $this->mw()->WriteStatusBar("Finish Drawing Energy Levels..."); } else { print("Drawing $TargetData...\n"); $mw->WriteStatusBar("Drawing $TargetData..."); $GraphFrameArray->Draw($canvas); print("Finish Drawing $TargetData...\n"); $mw->WriteStatusBar("Finish Drawing $TargetData..."); } } sub SetFileInfo { my ($this, $ListBox, $TextBox) = @_; return undef unless($ListBox); return undef unless($TextBox); $ListBox->ClearAll(); $TextBox->ClearText(); my $App = $this->App(); my @Font = split(/,/, $App->{"FileContentFont"}); $TextBox->configure(-font => \@Font) if(@Font > 0); my $DataArray = $App->TkData(); return undef unless($DataArray); my $GraphFrameArray = $this->GetGraphFrameArray(); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $GraphFrame0 = $pGraphFrame->[0]; my $pDataArray = $DataArray->DataArray(); return undef unless($pDataArray); my $Data = $pDataArray->GetGraphData(0); return undef unless($Data); if($this->FileType() eq "VASP Output file") { $ListBox->AddItem("EnergyConvergence"); $ListBox->AddItem("ForceConvergence(RMS)"); $ListBox->AddItem("ForceConvergence(AtomRange:1-3)"); $ListBox->AddItem("ForceConvergence"); $ListBox->AddItem("EnergyLevels"); } my $nData = $Data->nData(); my $title = $Data->Title(); $title = '' unless(defined $title); $TextBox->AddText("Title: $title\n"); $TextBox->AddText("$nData\n"); for(my $i = 0 ; $i < $nData ; $i++) { # my $x = $Data->x($i); my $str = ""; my $nX = $Data->nXColumn(); for(my $j = 0 ; $j < $nX ; $j++) { my $x = $Data->x($j, $i); next unless(defined $x); $x = sprintf("%7.3f", $x); $str = "$str\t$x"; } my $nY = $Data->nYColumn(); for(my $j = 0 ; $j < $nY ; $j++) { my $y = $Data->y($j, $i); next unless(defined $y); $y = sprintf("%9.3f", $y); my $convy = $GraphFrame0->YVal($y); $convy = sprintf("%9.3f", $convy); $str = "$str\t$y($convy)"; } $TextBox->AddText("$str\n"); } return 1; } #============================================================ # 一般関数 #============================================================ #============================================================ # bind応答関数 #============================================================ #注意:この関数がTkPlotWindow::SaveCSVFileの代わりに呼び出されることはない sub SaveCSVFile { my ($this) = @_; print "SaveCSVFile\n"; my $pGraphFrameArray = $this->GetGraphFrameArray(); for(my $i = 0 ; $i < $pGraphFrameArray->nGraphFrame() ; $i++) { my $pFrame = $pGraphFrameArray->GetGraphFrame($i); my ($y0, $y1) = $pFrame->GetViewYRange(); print "i=$i: Y = $y0 - $y1\n"; } my $ret = SUPER->SaveCSVFile(); $this->SetGraphFrameArray($pGraphFrameArray); return $ret; } sub ConfigureIniFileVariables { my ($this) = @_; my $App = $this->App(); $App->ConfigureIniFileVariables(); my $Style = $App->Args()->GetGetArg("style"); $Style = "General" unless($Style); # $App->AddIniFileVariable("\\$Style\\GraphFrame_Position", "GraphFramePosition", "r0.20,0.80,0.80,0.10"); $App->AddIniFileVariable("\\$Style\\GraphFrameDOS0_Position", "GraphFrameDOS0Position", "r0.20,0.80,0.80,0.45"); $App->AddIniFileVariable("\\$Style\\GraphFrameDOS1_Position", "GraphFrameDOS1Position", "r0.20,0.45,0.80,0.10"); $App->ReadSetting(); } 1;