OSDN Git Service

9de72e26649a26e1dd8a49d47c3f69edfcbc3844
[molby/Molby.git] / Scripts / startup.rb
1 #
2 #  startup.rb
3 #
4 #  Created by Toshi Nagata.
5 #  Copyright 2008 Toshi Nagata. All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation version 2 of the License.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 include Molby
17 include Math
18
19 Deg2Rad = Math::PI / 180.0
20 Rad2Deg = 180.0 / Math::PI
21
22 $startup_dir = Dir.pwd
23 case RUBY_PLATFORM
24   when /mswin|mingw|cygwin|bccwin/
25     $platform = "win"
26         $KCODE="SJIS"
27   when /darwin/
28     $platform = "mac"
29         $KCODE="UTF8"
30   else
31     $platform = "other"
32 end
33
34 $backtrace = nil
35
36 def backtrace
37   if $backtrace
38     print $backtrace.join("\n")
39   end
40 end
41
42 #  Utility methods
43 module Enumerable
44   def sum(&block)
45     if block
46       self.inject(0) { |sum, v| sum + block.call(v) }
47         else
48           self.inject(0) { |sum, v| sum + v }
49         end
50   end
51   def average(&block)
52     sum(&block) / Float(self.length)
53   end
54 end
55
56 module Kernel
57   def filecopy(src, dst)
58     fpin = File.open(src, "rb")
59     return nil if fpin == nil
60     fpout = File.open(dst, "wb")
61     if fpout == nil
62       fpin.close
63       return nil
64     end
65     a = ""
66     while fpin.read(4096, a)
67       fpout.write(a)
68     end
69     fpin.close
70     fpout.close
71     return true
72   end
73 end
74
75 load "transform.rb"
76 load "molecule.rb"
77 load "loadsave.rb"
78 load "formula.rb"
79 load "dialog.rb"
80 load "commands.rb"
81 load "md.rb"
82 load "uff.rb"
83 load "gamess.rb"
84 load "crystal.rb"
85
86 GC.start