package MOLDA; use Exporter; @ISA = qw(Exporter); #公開したいサブルーチン @EXPORT = qw(); use strict; use File::Basename; use Utils; use GraphData; use Sci::Science; use Sci::MolecularOrbital; use MyTk::GraphFrameArray; use Crystal::Molecule; use Crystal::AtomType; use Crystal::AtomSite; use Crystal::XCrySDen; use Crystal::CIF; #============================================================ # 変数等取得、再定義関数 #============================================================ sub ClearAll { my $this=shift; undef $this->{'FileType'}; undef $this->{'DataArray'}; } sub FileType { return shift->{'FileType'}; } sub FileName { return shift->{'FileName'}; } sub SetFileName { my ($this,$f)=@_; return $this->{'FileName'} = $f; } #sub DataArray { return shift->{'DataArray'}; } #sub SetDataArray { my ($this, $da) = @_; return $this->{'DataArray'} = $da; } sub SetSampleName { my ($this,$n)=@_; return $this->{'SampleName'} = $n; } sub SampleName { return shift->{'SampleName'}; } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CheckFileType { my ($path) = @_; #print "Gaussian::CheckFileType\n"; my ($drive, $dir, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); if($filename =~ /\.mld$/i) { return "MOLDA input file"; } return undef; } sub Read { my ($this, $filename) = @_; $this->ClearAll(); my $FileType = $this->{FileType} = MOPAC::CheckFileType($filename); $this->SetFileName($filename); #print "aFileType: $FileType\n"; if($FileType =~ /^MOPAC.*Output/i) { my $MO = $this->ReadMLDFile($filename); return $MO; } } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module) = @_; my $this = {}; bless $this; return $this; } sub DESTROY { my $this = shift; } #============================================================ # ファイル読み込み関数 #============================================================ #============================================================ sub SaveMldFileFromMolecule { my ($this, $path, $mol, $IsPrint) = @_; my $out = new JFile; $out->Open($path, "w") or return undef; print "Molecule: ", $mol->Title(), "\n" if($IsPrint); $out->print("\"", $mol->Title(), "\"\n"); $out->print($mol->nZMatrix(), "\n"); my $nSite = $mol->nAtomSite(); for(my $i = 0 ; $i < $nSite ; $i++) { my $site = $mol->GetCAtomSite($i); my $atomname = $site->AtomNameOnly(); my ($AtmNum, $name, $charge) = AtomType::GetAtomInformation($atomname); my ($x, $y, $z) = $site->Position(); $out->printf("%g,%g,%g,%d\n", $x, $y, $z, $AtmNum); printf("%g,%g,%g,%d\n", $x, $y, $z, $AtmNum) if($IsPrint); } $out->printf("%d\n", $mol->nZMatrix()-1); for(my $i = 1 ; $i < $mol->nZMatrix() ; $i++) { my $Z = $mol->ZMatrix($i); $out->printf("%d,%d,%d\n", $Z->{iAtom2}, $i+1, 1); } $out->Close(); return 1; } sub ReadMldFile { my ($this, $path, $TranslateToCenter, $IsPrint) = @_; my $mol = new Molecule; my $in = new JFile; if(!$in->Open($path, "r")) { return undef; } my $line = $in->ReadLine(1); Utils::DelQuote($line); $mol->SetTitle($line); print "Title: $line\n" if($IsPrint); my $nAtoms = $in->ReadLine(1); my %iAtom; for(my $i = 0 ; $i < $nAtoms ; $i++) { my $line = $in->ReadLine(1); last if($line eq ''); my ($x, $y, $z, $atomnum) = Utils::Split("\\s*,\\s*", $line); my $atomname = AtomType::GetAtomName($atomnum); $iAtom{$atomname}++; my $label = $atomname . $iAtom{$atomname}; $mol->AddAtomSite($label, $atomname, $x, $y, $z, 1.0); print "$label: $atomname ($x, $y, $z)\n" if($IsPrint); } $in->Close(); return $mol; } #============================================================ # 一般関数 #============================================================ 1;