package Atom; use Crystal::AtomType; @ISA = qw(AtomType); #公開したいサブルーチン @EXPORT = qw(); use strict; BEGIN { } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $AtomName) = @_; my $this = {}; bless $this; $this->SetAtomName($AtomName) if(defined $AtomName); return $this; } sub DESTROY { my $this = shift; } #============================================================ # 変数取得関数など #============================================================ sub SetLabel { my ($this, $Label) = @_; return $this->{Label} = $Label; } sub Label { my ($this) = @_; return $this->{'Label'}; } sub SetAtomName { my ($this, $IonName) = @_; return if(!defined $IonName); ($this->{AtomicNumber}, $this->{AtomNameOnly}, $this->{Charge}) = AtomType::GetAtomInformation($IonName); $this->{nElectron} = $this->{AtomicNumber} - $this->{Charge}; return $this->{AtomName} = $IonName; } sub AtomName { my ($this) = @_; return $this->{AtomName};; } sub AtomNameOnly { my ($this, $DelPar) = @_; my $name = $this->{AtomName}; $name =~ s/^([^\d+-]*)([\d+-\.]*)/$1/; $name =~ s/\{[^\{\}]*\}//g if($DelPar); return $name; } sub Charge { my ($this) = @_; my $charge = $this->{AtomName}; $this->{Charge} =~ s/^(\D*)(\d*)?([\+-]*)?/$2$3/; return $this->{Charge}; } sub AtomicNumber { my ($this) = @_; return $this->{AtomicNumber}; } sub nElectron { my ($this) = @_; return $this->{nElectron}; } sub nElectron { my ($this) = @_; return $this->{nElectron}; } sub SetPosition { my ($this,$x,$y,$z) = @_; $this->{x} = Sci::Round($x, 8); $this->{y} = Sci::Round($y, 8); $this->{z} = Sci::Round($z, 8); return ($x,$y,$z); } sub Position { my ($this,$IsReduce01) = @_; if($IsReduce01) { my $x = &Round01($this->{'x'}); my $y = &Round01($this->{'y'}); my $z = &Round01($this->{'z'}); return (Utils::Reduce01($x), Utils::Reduce01($y), Utils::Reduce01($z) ); } return ($this->{x}, $this->{y}, $this->{z}); } sub SetForce { my ($this,$fx,$fy,$fz) = @_; $this->{fx} = Sci::Round($fx, 8); $this->{fy} = Sci::Round($fy, 8); $this->{fz} = Sci::Round($fz, 8); return ($fx, $fy, $fz); } sub Force { my ($this) = @_; return ($this->{fx}, $this->{fy}, $this->{fz}); } sub SetVelocity { my ($this,$vx,$vy,$vz) = @_; $this->{vx} = $vx; $this->{vy} = $vy; $this->{vz} = $vz; return ($vx, $vy, $vz); } sub Velocity { my ($this) = @_; my $vx = $this->{vx}; my $vy = $this->{vy}; my $vz = $this->{vz}; return ($vx, $vy, $vz); } sub Occupancy { my ($this) = @_; return ($this->{'Occupancy'}); } sub SetOccupancy { my ($this,$occ) = @_; $occ = 1.0 if(!defined $occ); return $this->{'Occupancy'} = $occ; } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub Round01 { my ($x) = @_; return 1.0 if(abs($x - 1.0) < 0.0002); return 0.0 if(abs($x) < 0.001); return $x; } 1;