package SCIGRESS; use Exporter; @ISA = qw(Exporter); #公開したいサブルーチン @EXPORT = qw(); #use lib "d:/Programs/Perl/lib"; use strict; use File::Basename; use ProgVars; use Utils; use GraphData; use Sci::Science; use Sci::EnergyBandArray; #use MyTk::GraphFrameArray; use Crystal::Crystal; use Crystal::AtomType; use Crystal::AtomSite; use Crystal::XCrySDen; use Crystal::CIF; #=============================================== # スクリプト大域変数 #=============================================== my $LF = "
\n"; my $DirectorySeparator = Deps::DirectorySeparator(); #"\\"; #=============================================== # パス(読み込みDB) # Web関係変数 # CGI の仮想パス # プログラム名 #=============================================== my $Program = ProgVars::Program(); my $ProgramDir = ProgVars::ProgramDir(); my $ProgramOldDir = ProgVars::ProgramOldDir(); my $SCIGRESSDir = ProgVars::SCIGRESSDir(); my $WebRootDir = ProgVars::WebRootDir(); my $KListDBDir = ProgVars::KListDBDir(); #============================================================ # 変数等取得、再定義関数 #============================================================ sub ClearAll { my $this=shift; delete $this->{FileType}; delete $this->{DataArray}; } sub FileType { return shift->{FileType}; } sub FileName { return shift->{FileName}; } sub SetFileName { my ($this,$f)=@_; return $this->{'FileName'} = $f; } sub SetSampleName { my ($this,$n)=@_; return $this->{'SampleName'} = $n; } sub SampleName { return shift->{'SampleName'}; } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CheckFileType { my ($path) = @_; my ($drive, $dir, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); if($filename =~ /\.sim$/i) { return "SCIGRESS sim file"; } elsif($filename =~ /\.txt$/i) { return "SCIGRESS sim-converted text file"; } elsif($filename =~ /\.lst$/i) { return "SCIGRESS output LST file"; } return undef; } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module) = @_; my $this = {}; bless $this; return $this; } sub DESTROY { my $this = shift; } #============================================================ # 一般関数 #============================================================ sub SaveBDLFile { my ($this, $Crystal, $SaveFile, $ChooseRandomly, $IsPrint) = @_; $ChooseRandomly = 0 if(!defined $ChooseRandomly); $IsPrint = 1 if(!defined $IsPrint); my $out = JFile->new($SaveFile, "w"); unless($out) { print("

Error: Can not write to [$SaveFile]

\n") if($IsPrint); return; } my $CrystalName = $Crystal->CrystalName(); my $SuperLattice = $Crystal->GetCSuperLattice(); $Crystal = $SuperLattice if($SuperLattice); my ($a, $b, $c, $alpha, $beta, $gamma) = $Crystal->LatticeParameters(); my @AtomTypeList = $Crystal->GetCAtomTypeList(); my $nAtomType = @AtomTypeList; my @AtomSiteList = $Crystal->GetCExpandedAtomSiteList(); my $nAtomSite = @AtomSiteList; my %nAtom; for(my $i = 0 ; $i < $nAtomSite ; $i++) { my $site = $AtomSiteList[$i]; my $atomname = $site->AtomNameOnly(); $nAtom{$atomname}++; } print "nType: $nAtomType nSite: $nAtomSite\n" if($IsPrint); my $line = 1; if($IsPrint) { printf("Latt: %8f %8f %8f
\n", $a, $b, $c); printf("Latt: %8f %8f %8f
\n", $alpha, $beta, $gamma); printf("nAtomType: %2d %2d
\n", $nAtomType, 2); } $out->printf("%06d %8f %8f %8f\n", $line++, $a, $b, $c); $out->printf("%06d %8f %8f %8f\n", $line++, $alpha, $beta, $gamma); $out->printf("%06d %2d %2d\n", $line++, $nAtomType, 2); for(my $ia = 0 ; $ia < $nAtomType ; $ia++) { my $type = $AtomTypeList[$ia]; my $atomname = $type->AtomNameOnly(); my $charge = $type->Charge(); my $mass = $type->AtomicMass(); if($IsPrint) { printf("%-2s %3d %3d %3d
\n", $atomname, 1, $nAtom{$atomname}, 0); } $out->printf("%06d %-6s %3d %3d %3d\n", $line++, $atomname, 1, $nAtom{$atomname}, 0); for(my $is = 0 ; $is < $nAtomSite ; $is++) { my $site = $AtomSiteList[$is]; my $atomname1 = $site->AtomNameOnly(); my ($x,$y,$z) = $site->Position(1); next if($atomname1 ne $atomname); if($IsPrint) { printf("%-2s %8.3f %8.6f %8.6f %8.6f %8.4f
\n", $atomname, $charge, $x, $y, $z, $mass); } $out->printf("%06d %-4s %8.3f %15f %15f %15f %8.5f\n", $line++, $atomname, $charge, $x, $y, $z, $mass); } } $out->Close(); } sub ReadHeadingInforFromTXTFile { my ($this, $in) = @_; my ($nMDStep, $iOutputStep0, $nOutputInterval, @AtomTypes, $NATOM, $KMOL, @NUMMOL, @NUMATOM); my $line = $in->SkipTo("1st Record"); return undef if(!defined $line); $line = $in->SkipTo("NSTEP"); ($nMDStep) = ($line =~ /=\s*(\d+)/); print "nMDStep: $nMDStep\n"; $line = $in->SkipTo("MINIT"); ($iOutputStep0) = ($line =~ /=\s*(\d+)/); print "iOutputStep0: $iOutputStep0\n"; $line = $in->SkipTo("MINTV"); ($nOutputInterval) = ($line =~ /=\s*(\d+)/); print "nOutputInterval: $nOutputInterval\n"; $line = $in->SkipTo("NATOM"); ($NATOM) = ($line =~ /=\s*(\d+)/); print "nAtom: $NATOM\n"; $line = $in->SkipTo("KMOL"); ($KMOL) = ($line =~ /=\s*(\d+)/); print "KMOL: $KMOL\n"; $line = $in->SkipTo("I\\s+CHAMOL"); for(my $i = 0 ; $i < $KMOL ; $i++) { $line = $in->ReadLine(); my ($ID, $name, $IDYNAM, $NUMMOL, $NUMATOM, $nBond, $KINDAT) = Utils::Split("\\s+", $line); $name =~ s/\d//g; $AtomTypes[$i] = $name; $NUMMOL[$i] = $NUMMOL; $NUMATOM[$i] = $NUMATOM; print "at[$i]: $AtomTypes[$i] [NUMOL=$NUMMOL][NUMATOM=$NUMATOM]\n"; } return ($nMDStep, $iOutputStep0, $nOutputInterval, $NATOM, $KMOL, \@AtomTypes, \@NUMMOL, \@NUMATOM); } sub ReadNextStructureFromTXTFile { my ($this, $nStep, $in, $SampleName, $NATOM, $KMOL, $pAtomTypes, $pNUMMOL, $pNUMATOM) = @_; my $Crystal = new Crystal; $Crystal->SetCrystalName($SampleName); $Crystal->SetSampleName($SampleName); for(my $i = 0 ; $i < $NATOM ; $i++) { $Crystal->AddAtomType($pAtomTypes->[$i], 0); } my $line = $in->SkipTo("#\\s+STEP\\s+="); return undef if(!defined $line); $line = $in->SkipTo("Lattice Constants"); $in->ReadLine(); $line = $in->ReadLine(); my ($a, $b, $c) = Utils::Split("\\s+", $line); $in->ReadLine(); $line = $in->ReadLine(); my ($alpha, $beta, $gamma) = Utils::Split("\\s+", $line); $a += 0; $b += 0; $c += 0; $alpha += 0; $beta += 0; $gamma += 0; $Crystal->SetLatticeParameters($a, $b, $c, $alpha, $beta, $gamma); print "latt: $a, $b, $c, $alpha, $beta, $gamma\n"; $in->SkipTo("Lattice Coordinate"); $in->ReadLine(); $in->ReadLine(); $in->ReadLine(); $in->ReadLine(); for(my $i = 0 ; $i < $KMOL ; $i++) { my $atomtype = $pAtomTypes->[$i]; my $i1 = $i + 1; for(my $im = 0 ; $im < $pNUMMOL->[$i] ; $im++) { for(my $ia = 0 ; $ia < $pNUMATOM->[$i] ; $ia++) { $line = $in->ReadLine(); my ($I, $J, $K, $x, $y, $z) = Utils::Split("\\s+", $line); #print "at: $atomtype\n"; $Crystal->AddAtomSite("$atomtype$i1", $atomtype, $x, $y, $z, 1.0); #if($nStep % 50 == 0) { # print("$nStep:$i:$im:$ia: [$atomtype] ($x, $y, $z)\n"); #} } } } $Crystal->ExpandCoordinates(); return $Crystal; } sub ReadAtomTypesFromCSFFile { my ($this, $LSTPath) = @_; my %NameHash; my @AtomTypes; my $nAtomTypes = 0; my $in = new JFile($LSTPath, "rb"); return () if(!$in); $in->SkipTo("ID\\s+PDBName\\s+GroupType"); while(1) { my $line = $in->ReadLine(); my ($ID, $PDBName, $GroupType, $SSpdb, $AAcode, $name, $Chain) = Utils::Split("\\s+", $line); last if($ID !~ /^\d+$/); $name =~ s/\d//g; if(defined $NameHash{$name}) { } else { $NameHash{$name}++; $AtomTypes[$nAtomTypes] = $name; $nAtomTypes++; } } #for(my $i = 0 ; $i < $nAtomTypes ; $i++) { # print "name[$i]: $AtomTypes[$i]\n"; #} $in->Close(); return @AtomTypes; } sub ReadAtomTypesFromLSTFile { my ($this, $LSTPath) = @_; my ($nAtom, $KMOL, $nKAtom); my @AtomTypes; my $in = new JFile($LSTPath, "rb"); #binmode(STDOUT); return () if(!$in); $in->SkipTo("----\\s+NATOM"); my $line = $in->ReadLine(); ($nAtom, $KMOL, $nKAtom) = Utils::Split("\\s+", $line); print "n: $nAtom, $KMOL, $nKAtom\n"; for(my $i = 0 ; $i < $nKAtom ; $i++) { $in->SkipTo("----\\s+CHAMOL"); $line = $in->ReadLine(); #print "l: $line\n"; # $AtomTypes[$i] = $line; #print "l: [$AtomTypes[$i]]\n"; # $AtomTypes[$i] =~ s/\s.*$//; ($AtomTypes[$i]) =~ /(\w+)\x00/; print "$i: [$AtomTypes[$i]]\n"; } $in->Close(); return @AtomTypes; } 1;