Class: PoscarCommand
- Inherits:
-
Thor
- Object
- Thor
- PoscarCommand
- Defined in:
- bin/poscar
Overview
Command template
Instance Method Summary collapse
- #distance(*args) ⇒ Object
- #lattice_constants(*args) ⇒ Object
-
#povray(*args) ⇒ Object
‘-b conditions’,.
- #snapgeomopt ⇒ Object
- #substitute(*args) ⇒ Object
- #vaspdir ⇒ Object
- #vaspgeomopt ⇒ Object
Instance Method Details
#distance(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'bin/poscar', line 26 def distance(* args) if args.size > 3 puts "USAGE: poscar distance poscar_file [id1] [id2]" puts "Note: id count from 1" exit end poscar = VaspUtils::Poscar.load_file(args.shift) id = args.shift atom1s = [id.to_i] atom1s = 1..poscar.positions.size if id == nil id = args.shift atom2s = [id.to_i] atom2s = 1..poscar.positions.size if id == nil printf("atom1, atom2, %8s, %8s\n", "distance", "periodic_distance") atom1s.each do |atom1| atom2s.each do |atom2| index1 = atom1 - 1 index2 = atom2 - 1 cell = poscar.to_cell positions = cell.positions d = cell.distance(positions[index1], positions[index2]) #not periodic pcell = cell.to_pcell pd = pcell.nearest_distance(positions[index1], positions[index2]) #not periodic printf("%5i, %5i, %8.5f, %8.5f\n", atom1, atom2 , d, pd) end end end |
#lattice_constants(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'bin/poscar', line 12 def lattice_constants(* args) puts " a, b, c, alpha, beta, gamma, volume, file" args.each do |file| axes = VaspUtils::Poscar.load_file(file).axes latticeconstants = CrystalCell::LatticeAxes.axes_to_lc(axes) printf("%7.4f, %7.4f, %7.4f, %6.2f, %6.2f, %6.2f, ", *(latticeconstants)) printf("%8.3f, ", CrystalCell::Cell.new(axes).calc_volume) # show volume puts file end end |
#povray(*args) ⇒ Object
‘-b conditions’,
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'bin/poscar', line 113 def povray(* args) poscar = args[0] || 'POSCAR' tolerance = [:tolerance].to_f || 0.0 cell = VaspUtils::Poscar.load_file(poscar).to_cell(CrystalCell::Povray::Cell) puts cell.atoms_to_povs(tolerance).join puts cell.lattice_to_povs.join if [:bonds] elem0, elem1, min, max = ([:bonds].split(',')) puts cell.bonds_to_povs(elem0, elem1, min.to_f, max.to_f).join end end |
#snapgeomopt ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'bin/poscar', line 130 def snapgeomopt if [:xdatcar] xdatcar = VaspUtils::Xdatcar.load_file("./XDATCAR") positions_list = xdatcar.steps_positions elements = xdatcar.elements nums_elements = xdatcar.nums_elements bases = Array.new( positions_list.size).fill(xdatcar.axes) else xml = VaspUtils::VasprunXml.load_file("./vasprun.xml") bases = xml.bases positions_list = xml.positions_list elements = xml.elements nums_elements = xml.nums_elements end num_iteration = positions_list.size width = num_iteration.to_s.size bases.size.times do |i| prefix = sprintf("%0#{width}d", i +1) File.open(prefix + ".vasp", "w") do |io| poscar = VaspUtils::Poscar.new( hash = { :comment => "Generated by poscar_snapgeomopt, #{prefix}/#{num_iteration}", :scale => 1.0, :axes => bases[i], :elements => elements, :nums_elements => nums_elements, :selective_dynamics => false, :direct => 'direct', :positions => positions_list[i], } ) poscar.dump(io) end end end |
#substitute(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'bin/poscar', line 63 def substitute(* args) usage = "Usage: #{File.basename("#{__FILE__}")} POSCAR old_elem new_elem" poscar, elem1, elem2 = * args old_poscar = VaspUtils::Poscar.load_file(poscar) unless elem1 && elem2 num = old_poscar.elements.size width = 7 printf("%7s" * num, * old_poscar.elements) puts printf("%7d" * num, * old_poscar.nums_elements) puts exit end new_poscar = old_poscar.substitute(elem1, elem2) sum_old_radius = 0.0 old_poscar.elements.size.times do |i| radius = CrystalCell::Element.atomic_radius( old_poscar.elements[i]) sum_old_radius+= radius * old_poscar.nums_elements[i] end sum_new_radius = 0.0 new_poscar.elements.size.times do |i| radius = CrystalCell::Element.atomic_radius( new_poscar.elements[i]) sum_new_radius+= radius * new_poscar.nums_elements[i] end new_poscar.axes = old_poscar.axes.map{|axis| axis.map{|v| v * sum_new_radius/sum_old_radius}} new_poscar.dump($stdout) end |
#vaspdir ⇒ Object
171 172 173 174 175 |
# File 'bin/poscar', line 171 def vaspdir system "potcar generate --poscar > POTCAR" system "incar generate base singlepoint spin2 metal_geomopt --enmax130 > INCAR" system "kpoints generate --length=#{[:wavelength]} > KPOINTS" end |
#vaspgeomopt ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'bin/poscar', line 179 def vaspgeomopt poscar = VaspUtils::Poscar.load_file('POSCAR') es = poscar.elements ns = poscar.nums_elements dirname = '' poscar.elements.size.times do |i| dirname += es[i] dirname += ns[i].to_s end FileUtils.mkdir_p dirname subdir = dirname + '/geomopt00' FileUtils.mkdir_p subdir FileUtils.cp("POSCAR", subdir) system "potcar generate --poscar > #{subdir}/POTCAR" system "incar generate base full_relax spin2 metal_geomopt --enmax130=#{subdir}/POTCAR > #{subdir}/INCAR" system "kpoints generate --length=#{[:wavelength]} > #{subdir}/KPOINTS" end |