Error: Python input parse with "spring bond" constraint


Clicked A Few Times
Error:
cons_data: unable to get i_hbond_id 0

XYZ Geometry input file:
    17
 geometry
 C                     2.56053238     0.00000000    -0.32178249
 C                     1.28377833     0.00000000     0.52378962
 H                     2.60748061    -0.88346771    -0.96867846
 H                     3.45788510     0.00000000     0.30549716
 H                     2.60748061     0.88346771    -0.96867846
 C                     0.00000000     0.00000000    -0.31499271
 H                     1.28265917     0.87713360     1.18528745
 H                     1.28265917    -0.87713360     1.18528745
 C                    -1.28377833     0.00000000     0.52378962
 H                     0.00000000    -0.87767386    -0.97758617
 H                     0.00000000     0.87767386    -0.97758617
 C                    -2.56053238     0.00000000    -0.32178249
 H                    -1.28265917     0.87713360     1.18528745
 H                    -1.28265917    -0.87713360     1.18528745
 H                    -2.60748061     0.88346771    -0.96867846
 H                    -3.45788510     0.00000000     0.30549716
 H                    -2.60748061    -0.88346771    -0.96867846


Current Input file:
echo
title "Relax Carbon Chain"

permanent_dir ./perm
scratch_dir ./scratch

start carbon-chain-force

geometry units angstrom noautoz
    load carbon-chain-relaxed.xyz
end

basis 
    * library 6-31g**
end                                                                                            

dft 
    iterations 100
    xc b3lyp
    direct
end

python
    task_energy('dft')
    if (ga_nodeid() == 0):
        print "@@Marker1\n"

    input_parse('constraints; spring bond 1 12 5.0 10.0; end')
    if (ga_nodeid() == 0):
        print "@@Marker2\n"

    task_energy('dft')
    if (ga_nodeid() == 0):
        print "@@Marker3\n"
end


In interactive mode on an MPI-enabled node:
nwchem -n 8 inputFile | tee output

Output generated from "grep @@ output":
@@Marker1
@@Marker2

The error it exits with:
"cons_data: unable to get i_hbond_id 0"

So it seems the first energy calculation works fine, the second one errors out. This happens with task_optimize and task_gradient as well - which makes sense because those call the energy calculator.

Clicked A Few Times
Testing continued
After some more testing - I can put in another basis with the input_parse() command and it works fine. I can also put in a fixed atom constraint (as opposed to the spring bond) and it seems to run both energy calculations fine - which makes me think that it is erroring out when it is calculating the additive spring term to the energy? When it goes to calculate the second energy it says "The DFT is already converged", prints the DFT energy, then errors out.

If I instead run all the same commands from outside the python task there are no errors and it will do everything the same as above except after printing out "The DFT is already converged" it says "adding spring # 1" and prints out energy related to the spring:
task dft energy
constraints; spring bond 1 12 5.0 10.0; end
task dft energy


So at this point, it looks like an off-by-one error because when I call task_energy('dft') from within python, it searches for constraint 0 instead of constraint 1 (what is printed when I run it from the nwchem input file instead of the python script).

The next thing I tried though, was splitting up the python blocks:
python
    task_energy('dft')
    if (ga_nodeid() == 0):
        print "@@Marker1\n"
    input_parse('constraints; spring bond 1 12 5.0 10.0; end')
    if (ga_nodeid() == 0):
        print "@@Marker2\n"
end
task python
python
    task_energy('dft')                                                                         
    if (ga_nodeid() == 0):
        print "@@Marker3\n"
end
task python


This works. It seems that the rtdb is put into a working state between the task blocks.

Also, sorry for the duplicate posts below - please ignore them. I seemed to run into an ambiguous "URL not found" error pressing submit. Should have opened another browser window to see if changes were actually being applied.

Clicked A Few Times
Testing continued
Duplicate post edited down.

Clicked A Few Times
Testing continued
Duplicate post edited down.

Clicked A Few Times
Testing continued
Duplicate post edited down.

Clicked A Few Times
Testing continued
Duplicate post edited down.

Clicked A Few Times
More information
I've been searching around for a way to make the rtdb stay in a valid state after changing the spring constraint.

Adding a constraint in normal NWChem input leaves the rtdb in a valid state. Additionally, adding a constraint on the same two atoms later (whether in Python or in normal NWChem input) doesn't remove the constraint then re-add it, instead it just overwrites the constraint that's already there. So my solution was to add the constraint once before the python block using normal NWChem input, then in the Python block only to modify the existing constraint. This does not work though.

echo
title "Relax Carbon Chain"                                                                                             

permanent_dir ./perm
scratch_dir ./scratch

start carbon-chain-force

geometry units angstrom noautoz
    load carbon-chain-relaxed.xyz
end

basis
    * library 6-31g**
end

dft
    iterations 100
    xc b3lyp
    direct                                                                                                             
end

task dft optimize

constraints
    spring bond 1 12 0.00000642 184.78
end

python
    if (ga_nodeid() == 0):
        print "@@Marker1\n"

    task_optimize('dft')
    if (ga_nodeid() == 0):
        print "@@Marker2\n"

    input_parse('constraints; spring bond 1 12 0.00000642 369.57; end\n')
    if (ga_nodeid() == 0):
        print "@@Marker3\n"

    task_optimize('dft')
    if (ga_nodeid() == 0):
        print "@@Marker4\n"
end
task python


All four markers are reached, and the calculation ends successfully.

However, the new spring r0 is never actually applied. Looking through the output, it reads in the constraint information after Marker2 is reached, and looks like it's applying it. But in the optimization right after that, when it goes to add the spring energy to the DFT energy, it is still using the old spring (with r0 of 184.78). So it seems that input passed through "input_parse" is not treated the same as input passed in through the NWChem file. Changing the spring constant instead of the spring rest-length also doesn't seem to take.

For now I am relying on using a BASH script to unravel all the Python logic (looping over different spring lengths) to the NWChem input before running NWChem. But I would like to use the Python interface to dynamically change the initial spring length as it goes (in search of getting close to a list of specific forces). Also using the Python interface I can output the exact data I need as I go to a file, instead of processing the NWChem output afterward.


Forum >> NWChem's corner >> Running NWChem