File: scf.rb

package info (click to toggle)
psicode 3.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 46,400 kB
  • ctags: 18,552
  • sloc: cpp: 291,425; ansic: 12,788; fortran: 10,489; perl: 3,206; sh: 2,702; makefile: 2,207; ruby: 2,178; yacc: 110; lex: 53
file content (156 lines) | stat: -rw-r--r-- 4,319 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
58
59
60
61
62
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
# Handle access to Psi scf module
require 'pp'

module Psi
  class SCF
    include InputGenerator
    include Executor
    # Which references does this method support
    def self.supports_analytic_gradients
      { "rhf" => true, "rohf" => true, "uhf" => true, "twocon" => true }
    end
    def self.supports_analytic_second_derivatives
      { "rhf" => true, "rohf" => false, "uhf" => false, "twocon" => false }
    end
    
    def initialize(task_obj)
      @task = task_obj
      # Set the generic command for this class
      set_binary_command Psi::Commands::SCF
    end
  end
  
  # Add scf ability to Task
  class Task
    def scf(*args)
      # convert to a hash
      args_hash = args[0]
      
      # Make sure cints is called
      if args_hash != nil 
        if args_hash.has_key?(:ints) == false or 
           (args_hash.has_key?(:ints) and args_hash[:ints] == true)
          ints("wfn" => "scf")
        end
      else
        ints("wfn" => "scf")
      end

      # Create a new scf object
      scf_obj = Psi::SCF.new self

      # Form the input hash and generate the input file
      input_hash = { }

      # Check to see if the user overrode the wavefunction
      if args_hash == nil or args_hash.has_key?("wfn") == false
        input_hash["wfn"] = wavefunction
      else
        input_hash["wfn"] = args_hash["wfn"]
      end
      args_hash.delete("wfn") unless args_hash == nil

      # Check to see if the user gave the reference wavefunction. if it is given, do not use the
      # global setting
      if args_hash == nil or args_hash.has_key?("reference") == false
        input_hash["reference"] = reference
      else
        input_hash["reference"] = args_hash["reference"]
      end
      args_hash.delete("reference") unless args_hash == nil

      # If we are doing analytical gradients then cscf needs to know
      if get_gradients == true and SCF.supports_analytic_gradients[reference] == true
        input_hash["dertype"] = "first"
      elsif get_second_deriv == true and SCF.supports_analytic_second_derivatives[reference] == true
        input_hash["dertype"] = "second"
      else
        input_hash["dertype"] = "none"
      end

      # Merge what we've done with what the user wants
      input_hash = input_hash.merge(args_hash) unless args_hash == nil

      # Run the scf module, sending the input file as keyboard input
      puts "scf"
      scf_obj.execute(input_hash)

      # Check to see if we are supposed to compute analytical gradients, only do if
      #  1. It is supported
      #  2. The user requested it
      #  3. The wavefunction is SCF
      if get_gradients == true and SCF.supports_analytic_gradients[reference] == true and wavefunction.casecmp("scf") == 0
        # Make sure the wavefunction is set
        input_hash["wfn"] = "scf"
        deriv(input_hash)
      elsif get_second_deriv == true and SCF.supports_analytic_second_derivatives[reference] == true and wavefunction.casecmp("scf") == 0
        # Make sure the wavefunction is set
        input_hash["wfn"] = "scf"
        transqt(input_hash)
        deriv2(input_hash)
        propint(input_hash)
        cphf(input_hash)
      end
      
      # Return the total energy to the user
      etot
    end

    def rhf(*args)
      # Convert to hash
      args_hash = args[0]

      # Set the Task reference to RHF
      # Must use @ sign here to access the instance variable, if we did reference then only
      # local variable is set
      @reference = "rhf"

      # Call scf
      scf(args_hash)
    end

    def rohf(*args)
      args_hash = args[0]

      # Set the Task reference to ROHF
      @reference = "rohf"

      # Call scf
      scf(args_hash)
    end

    def uhf(*args)
      args_hash = args[0]

      # Set the global reference to UHF
      @reference = "uhf"

      # Call scf
      scf(args_hash)
    end    
  end
end

# Create some global functions
# User can send additional input parameters to the function
def scf(*args)
  # convert to a hash
  args_hash = args[0]
  Psi::global_task.scf(args_hash)
end

def rhf(*args)
  # Convert to hash
  args_hash = args[0]
  Psi::global_task.rhf(args_hash)
end

def rohf(*args)
  args_hash = args[0]
  Psi::global_task.rohf(args_hash)
end

def uhf(*args)
  args_hash = args[0]
  Psi::global_task.uhf(args_hash)
end