Example: partial charges and total charge¶
This example shows you some ways to use partial atomic charges for ions. The atomic charges should add up to the total charge.
#!/bin/sh
# Here we consider a Butane molecule with the C in the end groups changed to N
# The ion has a charge of plus two.
# The (partial) atomic charges used in the forcefield need to add up to the total charge
# There is explicit specification via the input, Loading charges, and guessing charges
# Charges taken "manually" from a DFTB calc., specified via the System%Atoms block
export AMS_JOBNAME=C2H10N2++
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-0.224106970135964811E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=0.481803346892513140E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=0.481357488383262755E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.224111043229265006E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=0.327048167700910608E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.312019677649949589E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.312016700963803795E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.112420754799849087E+000
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.112425859786873958E+000
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.112415997624231642E+000
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.112419970108937881E+000
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.312043881750391661E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.312048243703216099E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.327042675749500744E+000
End
GuessBonds True
Charge 2.0
End
Engine ForceField
EndEngine
eor
# Now the neutral molecule, to show it behaves differently
export AMS_JOBNAME=C2H10N2
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-0.571011278205044492E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=-0.628203646719944775E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=-0.628837746183146251E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.571125568500377101E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=0.194366247283714433E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.194416030458134853E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.194415295916033237E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.253223131130085044E-001
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.253801306729796901E-001
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.253595653793994673E-001
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.254060553518517668E-001
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.194371032691725371E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.194368207022870332E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.194436108106012751E+000
End
GuessBonds True
End
Engine ForceField
EndEngine
eor
# The remaining calculations are again on the +2 ion
# Charges obtained with GuessCharges, using by default dftb.
export AMS_JOBNAME=C2H10N2++.guessed
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219
N 0.7166487936613554 -1.241183181538415 -2.471469363728673
H -0.489254727061788 0.8470579056083724 1.393322418122902
H 0.9419603270459358 0.02859511576851682 1.443864570589139
H -0.4954439060007188 -0.801643243084588 1.443905390218997
H 0.497012567535054 0.9247340386709353 -0.7538297483507286
H -1.049427360359161 0.0320094307806696 -0.7537906795101232
H 1.760678843023289 -1.264262738726653 -0.6572703272452628
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752
H 1.207324110469442 -0.4308282262683778 -2.854859298860555
H -0.2304034502578771 -1.260970512043685 -2.855040966499596
H 1.200917269444972 -2.079821003490794 -2.803581935602674
End
GuessBonds True
Charge 2.0
End
Engine ForceField
GuessCharges True
EndEngine
eor
# Charges are now both specified on input and also Guessed
# The values on the input (ForceField.Charge) are on purpose unreasonable
# The Guessed charges have a higher priority and the input values are ignored
# The output is a bit confusing as unused ForceField.Charge is printed
export AMS_JOBNAME=C2H10N2++.inputandguessed
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-1.224106970135964811E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=0.481803346892513140E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=0.481357488383262755E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.224111043229265006E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=1.327048167700910608E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.312019677649949589E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.312016700963803795E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.112420754799849087E+000
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.112425859786873958E+000
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.112415997624231642E+000
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.112419970108937881E+000
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.312043881750391661E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.312048243703216099E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.327042675749500744E+000
End
GuessBonds True
Charge 2.0
End
Engine ForceField
GuessCharges True
EndEngine
eor
# Charges obtained with Load Charges from a DFTB calc.
export AMS_JOBNAME=C2H10N2++.dftb
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task SinglePoint
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219
N 0.7166487936613554 -1.241183181538415 -2.471469363728673
H -0.489254727061788 0.8470579056083724 1.393322418122902
H 0.9419603270459358 0.02859511576851682 1.443864570589139
H -0.4954439060007188 -0.801643243084588 1.443905390218997
H 0.497012567535054 0.9247340386709353 -0.7538297483507286
H -1.049427360359161 0.0320094307806696 -0.7537906795101232
H 1.760678843023289 -1.264262738726653 -0.6572703272452628
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752
H 1.207324110469442 -0.4308282262683778 -2.854859298860555
H -0.2304034502578771 -1.260970512043685 -2.855040966499596
H 1.200917269444972 -2.079821003490794 -2.803581935602674
End
Charge 2.0
End
Engine DFTB
EndEngine
eor
loadChargeFile='C2H10N2++.dftb.results/dftb.rkf'
export AMS_JOBNAME=C2H10N2++.loaded
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219
N 0.7166487936613554 -1.241183181538415 -2.471469363728673
H -0.489254727061788 0.8470579056083724 1.393322418122902
H 0.9419603270459358 0.02859511576851682 1.443864570589139
H -0.4954439060007188 -0.801643243084588 1.443905390218997
H 0.497012567535054 0.9247340386709353 -0.7538297483507286
H -1.049427360359161 0.0320094307806696 -0.7537906795101232
H 1.760678843023289 -1.264262738726653 -0.6572703272452628
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752
H 1.207324110469442 -0.4308282262683778 -2.854859298860555
H -0.2304034502578771 -1.260970512043685 -2.855040966499596
H 1.200917269444972 -2.079821003490794 -2.803581935602674
End
GuessBonds True
Charge 2.0
End
Engine ForceField
LoadCharges
File $loadChargeFile
End
EndEngine
eor
# Charges are now both specified on input and also Guessed
# The values on the input (ForceField.Charge) are on purpose unreasonable
# The Guessed charges have a higher priority and the input values are ignored
# The output is a bit confusing as unused ForceField.Charge is printed
export AMS_JOBNAME=C2H10N2++.inputandloaded
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-1.224106970135964811E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=0.481803346892513140E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=0.481357488383262755E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.224111043229265006E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=1.327048167700910608E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.312019677649949589E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.312016700963803795E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.112420754799849087E+000
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.112425859786873958E+000
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.112415997624231642E+000
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.112419970108937881E+000
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.312043881750391661E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.312048243703216099E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.327042675749500744E+000
End
GuessBonds True
Charge 2.0
End
Engine ForceField
LoadCharges
File $loadChargeFile
End
EndEngine
eor
# this calculation should succeed, ignoring the default zero total charge and using the atomic charges instead
export AMS_JOBNAME=C2H10N2++.warning
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-0.224106970135964811E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=0.481803346892513140E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=0.481357488383262755E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.224111043229265006E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=0.327048167700910608E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.312019677649949589E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.312016700963803795E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.112420754799849087E+000
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.112425859786873958E+000
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.112415997624231642E+000
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.112419970108937881E+000
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.312043881750391661E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.312048243703216099E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.327042675749500744E+000
End
GuessBonds True
End
Engine ForceField
EndEngine
eor
# this calculation should trigger a warning because the explicitly set Charge doesn't match
export AMS_JOBNAME=C2H10N2++.warning
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-0.224106970135964811E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=0.481803346892513140E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=0.481357488383262755E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.224111043229265006E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=0.327048167700910608E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.312019677649949589E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.312016700963803795E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.112420754799849087E+000
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.112425859786873958E+000
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.112415997624231642E+000
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.112419970108937881E+000
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.312043881750391661E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.312048243703216099E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.327042675749500744E+000
End
GuessBonds True
Charge 1.0
End
Engine ForceField
EndEngine
eor
# finally let us make on purpose an error (total charge not set with strict checking enabled)
# this calculation is supposed to fail, and not print an energy
echo "The following error is intended"
export AMS_JOBNAME=C2H10N2++.inputerror
rm -rf $AMS_JOBNAME.results
"$AMSBIN/ams" << eor
Task GeometryOptimization
Properties Charges=yes
GeometryOptimization
Convergence Gradients=1.0e-6
End
System
Atoms
N -0.005073166519502884 0.008770355996886468 1.060120635725228 ForceField.Charge=-0.224106970135964811E+000
C -0.003379615065181385 0.005774705419397744 -0.4323726711546611 ForceField.Charge=0.481803346892513140E-001
C 0.7147029862216027 -1.238161594687982 -0.9787933548287219 ForceField.Charge=0.481357488383262755E-001
N 0.7166487936613554 -1.241183181538415 -2.471469363728673 ForceField.Charge=-0.224111043229265006E+000
H -0.489254727061788 0.8470579056083724 1.393322418122902 ForceField.Charge=0.327048167700910608E+000
H 0.9419603270459358 0.02859511576851682 1.443864570589139 ForceField.Charge=0.312019677649949589E+000
H -0.4954439060007188 -0.801643243084588 1.443905390218997 ForceField.Charge=0.312016700963803795E+000
H 0.497012567535054 0.9247340386709353 -0.7538297483507286 ForceField.Charge=0.112420754799849087E+000
H -1.049427360359161 0.0320094307806696 -0.7537906795101232 ForceField.Charge=0.112425859786873958E+000
H 1.760678843023289 -1.264262738726653 -0.6572703272452628 ForceField.Charge=0.112415997624231642E+000
H 0.2140471968077103 -2.156981931600252 -0.6574882069415752 ForceField.Charge=0.112419970108937881E+000
H 1.207324110469442 -0.4308282262683778 -2.854859298860555 ForceField.Charge=0.312043881750391661E+000
H -0.2304034502578771 -1.260970512043685 -2.855040966499596 ForceField.Charge=0.312048243703216099E+000
H 1.200917269444972 -2.079821003490794 -2.803581935602674 ForceField.Charge=0.327042675749500744E+000
End
GuessBonds True
End
Engine ForceField
DoChargeCheck True
EndEngine
eor