topas-tools 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebd3b0096d76533b4ad2b3b29d13e9c0fb440ec2
4
- data.tar.gz: 3f9822ab33d2135dda7593b0d7fcea801feef74f
3
+ metadata.gz: 5ad5733a79ab858d041879381d154d5d4035b1d5
4
+ data.tar.gz: 6ac694b38871a0953ff1c98c6eed806418800f50
5
5
  SHA512:
6
- metadata.gz: 391701df3da48ef07f27893af04a5aa73deaad6bfc4782b5691d9e2991e861fb1da4b153ecdab7d5be71448f7f61a1eb8976ab29b7d94ba691277dc89b35fdd1
7
- data.tar.gz: 2175813c9d94dcd5593b8796d4229607a63aedb09bc3e5adf280e0256651b80dedb7d820e6b9bf2bebc6d2d1a8db2209cb0b8ba69190700354f672931e5937fb
6
+ metadata.gz: edf7529c615d17dc0574b31f0e9777ad18e7c481e2f501207fd892c873c9c7dc1f656cb52ce3a446efb6e65cc1cb4c32f59b1e7b5fd08e5cc6ad7754c2d01bf1
7
+ data.tar.gz: 20999ca2835dd96b60939b29ded5430aca43cfa3e2999eda1db4884f314aaf62193f7f7ece0d0cc666bfab8f1830e3cdd4c0ec062de32f8d08cb1d03e6ba8080
data/bin/toparun CHANGED
@@ -5,14 +5,14 @@ require 'optparse'
5
5
  require 'topas-tools'
6
6
 
7
7
 
8
- options = {points:[100.0, 16.0, 0.0], steps:[4.0, 1.0], smart:false, system: :wine}
8
+ options = {points:[100.0, 15.0, 0.25], steps:[4.0, 1.0], smart:false, system: :wine, topasdir:'/home/dmitrienka/.wine/drive_c/TOPAS4-2/'}
9
9
  OptionParser.new do |opts|
10
- opts.banner = "Usage: toparun.rb [-p 100,15,0 -s 1,0.25] filename.inp"
10
+ opts.banner = "Usage: toparun.rb [-p 100,15,0.25 -s 4,1] filename.inp"
11
11
  opts.on("-p", "--points LIST", Array ,"Array of points, representing intervals with different stepsizes"){|list|
12
12
  options[:points] = list.map(&:to_f)}
13
13
  opts.on("-s", "--steps LIST", Array ,"Well, stepsizes for that intervals"){|list|
14
14
  options[:steps] = list.map(&:to_f)}
15
- opts.on("-s", "--[no-]smart", "Gone smart!") do |s|
15
+ opts.on("-S", "--[no-]smart", "Gone smart!") do |s|
16
16
  options[:smart] = s
17
17
  end
18
18
  opts.on("--system [SYS]", [:windows, :wine, :dummy],
@@ -23,12 +23,11 @@ end.parse!
23
23
 
24
24
  ARGV[0] || raise("Rrrr! Where is my input file??")
25
25
 
26
- TopasEngine.system = options[:system]
27
-
28
-
29
- runner = TopasEngine.new
30
- input = TopasInput.new IO.read(ARGV[0], :encoding => "UTF-8"),
31
- ARGV[0].sub(/\..{2,3}$/, '')
32
-
33
- runner.refine input, options[:points], options[:steps], (options[:smart] ? QuantileAnalyzer.new : BaseAnalyzer.new)
34
-
26
+ dir = File.expand_path File.dirname ARGV[0]
27
+ name = File.basename(ARGV[0], File.extname(ARGV[0]))
28
+ text = IO.read(ARGV[0], :encoding => "UTF-8")
29
+ engine = TopasEngine.create options[:system], options[:topasdir]
30
+ input = TopasInput.new text, name
31
+ steps = Steps.new options[:points], options[:steps]
32
+ runner = Metarefine.new engine, input, dir, steps
33
+ runner.toparun BaseAnalyzer.new
data/bin/toparunGUI CHANGED
@@ -8,7 +8,7 @@ require 'topas-tools'
8
8
  Shoes.app :width => 400, :height => 800 do
9
9
 
10
10
  @log = StringIO.new
11
- @log.write "Hi, log starts here!\n"
11
+ @log.write "k1\tR_wp\tMax dev.\tMultiplier\tOutlier\n"
12
12
 
13
13
  #base flow
14
14
  flow :margin=>10 do
@@ -39,7 +39,7 @@ Shoes.app :width => 400, :height => 800 do
39
39
  end
40
40
 
41
41
  flow do
42
- para "Stepss:"
42
+ para "Steps:"
43
43
  @stepsline = edit_line
44
44
  @stepsline.text = "4,1"
45
45
  end
@@ -59,11 +59,17 @@ Shoes.app :width => 400, :height => 800 do
59
59
  end
60
60
 
61
61
  Thread.new(points, steps, @log ) do |points, steps|
62
- inp = @inpline.text
62
+
63
+ inp = @inpline.text
64
+ dir = File.expand_path File.dirname inp
65
+ name = File.basename(inp, File.extname(inp))
66
+ text = IO.read(inp, :encoding => "UTF-8")
63
67
  engine = TopasEngine.create @systemlist.text.to_sym, @topasdir.text
64
- input = TopasInput.new IO.read(inp, :encoding => "UTF-8"), inp
65
- runner = Metarefine.new engine, input, File.dirname(inp), Steps.new(points, steps)
66
- runner.toparun BaseAnalyzer.new(@log)
68
+ input = TopasInput.new text, name
69
+ steps = Steps.new points, steps
70
+ runner = Metarefine.new engine, input, dir, steps
71
+ runner.toparun BaseAnalyzer.new(@log)
72
+
67
73
  @clear = button 'Clear' do
68
74
  @log = StringIO.new
69
75
  @clear.clear
@@ -71,9 +77,8 @@ Shoes.app :width => 400, :height => 800 do
71
77
  end
72
78
  end
73
79
 
74
- para self
75
80
  caption "Log:"
76
- stack :width => 300, :margin => 20 do
81
+ stack :width => 370, :margin => 20 do
77
82
 
78
83
 
79
84
  @paralog = para
@@ -1,17 +1,55 @@
1
1
  class BaseAnalyzer
2
+
3
+ K1TABLE = [5.62619251369954 ,3.59689767105988, 2.99683950381941, 2.9141936236358 , 3.37232041437195 ,2.93196313616901, 2.72771585462825, 2.70417682172506, 2.86576896853064 ,2.66921102377684, 2.57092705221669, 2.55881443841962, 2.64995441497466 ,2.53075618782533, 2.47791909362932, 2.4741828679544 , 2.53384546494551 ,2.45983379319381, 2.4212286638301 , 2.4159429171073 , 2.45784825894735 ,2.40879237590095, 2.38090443345185, 2.38216835038994, 2.41048201093783 ,2.36989342570794, 2.35215022384351, 2.3524695182014, 2.37772035649117 ,2.34643406722578, 2.33269558844597, 2.33379314746303, 2.35213581186961 ,2.3293126888992 , 2.31585973838799, 2.32211834728897, 2.33719246258054 ,2.31822219208683, 2.30836925652429, 2.30928647548234, 2.32053355883361 ,2.30880999917026, 2.29983955811199, 2.30081635190135, 2.31427557030017 ,2.29827012906655]
4
+
2
5
  def initialize output = $stdout
3
6
  @out = output
4
7
  @count = 0
8
+ @rtable = []
5
9
  end
6
10
 
7
11
  def analyze inp
8
- @out.print "Analizing #{inp.name}... \n"
12
+ restrains = inp.restrains
13
+ restrains.each do |r|
14
+ @rtable << {k1:inp.k1, r_wp:inp.r_wp, name:r[:name],
15
+ delta:(r[:value] - r[:restrain])}
16
+ end
17
+ @name = inp.base_name
18
+ errors = restrains.map{|r| r[:value] - r[:restrain]}
19
+ mdev = max_dev(errors)
20
+ mult = K1TABLE[restrains.size - 5]
21
+ outlier = (mdev > mult ? "x" : "o")
22
+ @out.print "%d\t%0.3f\t%0.3f\t%0.3f\t#{outlier}\n" % [inp.k1, inp.r_wp, mdev, mult]
9
23
  @count = @count + 1
10
24
  true
11
25
  end
26
+
12
27
 
13
28
  def report
14
29
  @out.print "Refinement was finished in #{@count} steps.\n"
30
+ file = File.open("#{@name}_rtable.dat", 'w')
31
+ file.write("K1\tRwp\tBond\tDelta\tError\n")
32
+ @rtable.each do |rt|
33
+ file.write("#{rt[:k1]}\t#{rt[:r_wp]}\t#{rt[:name]}\t#{rt[:delta]}\t0\n")
34
+ end
35
+ file.close
15
36
  true
16
37
  end
38
+
39
+ private
40
+
41
+ def quantile7 p, x
42
+ n = x.size
43
+ sorted = x.sort
44
+ j = (n*p - p +1).floor
45
+ g = n*p - p + 1 - j
46
+ (1 - g) * sorted[j - 1] + g * sorted[j]
47
+ end
48
+
49
+ def max_dev x
50
+ q1 = quantile7 0.25, x
51
+ q3 = quantile7 0.75, x
52
+ iqr = q3 - q1
53
+ [(q1 - x.min)/iqr, (x.max-q3)/iqr].max
54
+ end
17
55
  end
@@ -27,10 +27,10 @@ class Metarefine
27
27
  def toparun analyzer, work_dir = File.expand_path(@input.base_name)
28
28
  Dir.mkdir(work_dir) unless Dir.exists? work_dir
29
29
  @steps.k1s.reduce(@input) do |inp, k1|
30
- out = @engine.tc work_dir inp.set_k1(k1)
30
+ out = @engine.tc work_dir, inp.set_k1(k1)
31
31
  analyzer.analyze(out) ? out : break
32
32
  end
33
- Dir.chdir @base_dir
33
+ Dir.chdir @basedir
34
34
  analyzer.report
35
35
  end
36
36
  end
@@ -5,9 +5,10 @@ class TopasInput
5
5
  @base_name = get_base_name base_name
6
6
  @name = get_name
7
7
  @restrains = get_restrains
8
+ @r_wp = get_rwp
8
9
  end
9
10
 
10
- attr_reader :k1, :name, :base_name, :restrains, :text
11
+ attr_reader :k1, :name, :base_name, :restrains, :text, :r_wp
11
12
 
12
13
 
13
14
  def set_k1!(num)
@@ -48,6 +49,11 @@ class TopasInput
48
49
  @text.scan(/penalties_weighting_K1\s+([\d.]+)/)[0][0].to_f
49
50
  end
50
51
 
52
+ def get_rwp
53
+ @text.scan(/r_wp\s+([\d.]+)/)[0][0].to_f
54
+ end
55
+
56
+
51
57
  def get_base_name bn
52
58
  if bn
53
59
  base_name = File.basename(bn, File.extname(bn))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topas-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Dmitrienko