~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to tools/moltemplate/common/amber/amberparm2lt.sh

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2013-11-20 22:41:36 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131120224136-tzx7leh606fqnckm
Tags: 0~20131119.git7162cf0-1
* [e65b919] Imported Upstream version 0~20131119.git7162cf0
* [f7bddd4] Fix some problems, introduced by upstream recently.
* [3616dfc] Use wrap-and-sort script.
* [7e92030] Ignore quilt dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
if ! which amberparm_mass_to_lt.py > /dev/null; then
 
4
    echo "\nError: \"amberparm_mass_to_lt.py\" not found. (Update your PATH?)\n" >&2
 
5
    exit 2
 
6
fi
 
7
if ! which amberparm_pair_to_lt.py > /dev/null; then
 
8
    echo "\nError: \"amberparm_pair_to_lt.py\" not found. (Update your PATH?)\n" >&2
 
9
    exit 2
 
10
fi
 
11
if ! which amberparm_bond_to_lt.py > /dev/null; then
 
12
    echo "\nError: \"amberparm_bond_to_lt.py\" not found. (Update your PATH?)\n" >&2
 
13
    exit 2
 
14
fi
 
15
if ! which amberparm_angle_to_lt.py > /dev/null; then
 
16
    echo "\nError: \"amberparm_angle_to_lt.py\" not found. (Update your PATH?)\n" >&2
 
17
    exit 2
 
18
fi
 
19
if ! which amberparm_dihedral_to_lt.py > /dev/null; then
 
20
    echo "\nError: \"amberparm_dihedral_to_lt.py\" not found. (Update your PATH?)\n" >&2
 
21
    exit 2
 
22
fi
 
23
if ! which amberparm_improper_to_lt.py > /dev/null; then
 
24
    echo "\nError: \"amberparm_improper_to_lt.py\" not found. (Update your PATH?)\n" >&2
 
25
    exit 2
 
26
fi
 
27
 
 
28
SYNTAX_MSG=$(cat <<EOF
 
29
Typical Usage:
 
30
 
 
31
amberparm2lt.sh gaff.dat GAFF > gaff.lt
 
32
 
 
33
  You can also try:
 
34
amberparm2lt.sh parm94.dat "AMBERFF94 inherits GAFF" > amberff94.lt
 
35
  (However, this later usage may not work.
 
36
  You may need to manually split the .dat file and run these scripts instead:
 
37
  amberparm_pair_to_lt.py, amberparm_bond_to_lt.py, amberparm_angle_to_lt.py...)
 
38
  Be sure that all of these .py files are in your PATH as well.)
 
39
 
 
40
EOF
 
41
)
 
42
 
 
43
if [ "$#" != "2" ]; then
 
44
    echo "${SYNTAX_MSG}" >&2
 
45
    echo "" >&2
 
46
    echo "Error: This script requires two arguments," >&2
 
47
    echo "       1) the name of the amber parm file to be converted (eg \"gaff.dat\")" >&2
 
48
    echo "       2) the name of the moltemplate object to be created (eg \"GAFF\")" >&2
 
49
    echo "          (This may include the \"inherits\" keyword and parent classes.)" >&2
 
50
    exit 1
 
51
fi
 
52
 
 
53
MOLTEMPLATE_USAGE_MSG=$(cat <<EOF
 
54
#    Background information and usage explanation:
 
55
# This file contanis a list of atom types and rules for generating bonded
 
56
# interactions between these atoms (hopefully) according to AMBER conventions.
 
57
# By using the atom types shown below in your own molecules, bonds and angular 
 
58
# interactions will be automatically generated.
 
59
# AMBER (GAFF) force-field parameters will also be assigned to each angle
 
60
# interaction (according to these atom types).
 
61
# One way to apply the GAFF force field to a particular type of molecule, is
 
62
# to use the "inherits" keyword when you define that molecule.  For example:
 
63
# import("gaff.lt")
 
64
# MoleculeType inherits GAFF {
 
65
#   write_once("Data Atoms") {
 
66
#     \$atom:C1 \$mol:... @atom:cx 0.0 4.183 3.194 13.285
 
67
#     \$atom:C2 \$mol:... @atom:cx 0.0 4.291 4.618 13.382
 
68
#        :       :         :
 
69
#   }
 
70
# }
 
71
#(See "Inheritance" and "short names vs. full names" in the moltemplate manual.)
 
72
EOF
 
73
)
 
74
# (Note that the full name of the atom type in this example is "@atom:/GAFF/cx"
 
75
#  You can always refer to atom types this way as well.  Using "inherits GAFF"
 
76
#  allows you to use more conventient "@atom:cx" shorthand notation instead.)
 
77
 
 
78
echo "####################################################################"
 
79
echo "# To use this, LAMMPS currently must be compiled with the USER-MISC package."
 
80
echo "# (Type \"make yes-user-misc\" into the shell before compiling LAMMPS.)"
 
81
echo "####################################################################"
 
82
echo "#    This moltemplate (LT) file was generated automatically using"
 
83
echo "# amberparm2lt.sh $1 $2"
 
84
echo "####################################################################"
 
85
echo "$MOLTEMPLATE_USAGE_MSG"
 
86
echo "####################################################################"
 
87
echo "#    Moltemplate can not assign atom charge.  You must assign atomic"
 
88
echo "# charges yourself.  (Moltemplate is only a simple text manipulation tool.)"
 
89
echo "####################################################################"
 
90
echo ""
 
91
echo ""
 
92
 
 
93
 
 
94
#PARM_FILE='gaff.dat'
 
95
PARM_FILE=$1
 
96
 
 
97
# sections are separated by blank lines
 
98
# some sections have comment lines at the beginning
 
99
 
 
100
# The 1st section is the mass (note: skip the first line)
 
101
tail -n +2 < "$PARM_FILE" | \
 
102
    awk -v n=1 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
103
    > "${PARM_FILE}.mass"
 
104
 
 
105
# The 2nd section has the list of 2-body bond force-field params
 
106
awk -v n=2 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
107
    < "$PARM_FILE" \
 
108
    | tail -n +2 \
 
109
    > "${PARM_FILE}.bond"
 
110
 
 
111
# The 3rd section has the list of 3-body angle force-field params
 
112
awk -v n=3 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
113
    < "$PARM_FILE" \
 
114
    > "${PARM_FILE}.angle"
 
115
 
 
116
# The 4th section has the list of 4-body dihedral force-field params
 
117
awk -v n=4 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
118
    < "$PARM_FILE" \
 
119
    > "${PARM_FILE}.dihedral"
 
120
 
 
121
# The 5th section has the list of 4-body improper force-field params
 
122
awk -v n=5 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
123
    < "$PARM_FILE" \
 
124
    > "${PARM_FILE}.improper"
 
125
 
 
126
# The 6th section has the hbond-parameters (no-longer used.  ignore)
 
127
awk -v n=6 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
128
    < "$PARM_FILE" \
 
129
    > "${PARM_FILE}.hbond"
 
130
 
 
131
# The 7th "section" is just a blank line.  (skip that)
 
132
 
 
133
# The 8th section has the list of non-bonded ("pair") force-field parameters
 
134
awk -v n=8 '{if (NF==0) nblanks++; else {if (nblanks+1==n) print $0}}' \
 
135
    < "$PARM_FILE" \
 
136
    | tail -n +2 \
 
137
    > "${PARM_FILE}.pair"
 
138
 
 
139
 
 
140
amberparm_mass_to_lt.py < "${PARM_FILE}.mass" > "${PARM_FILE}.mass.lt"
 
141
amberparm_pair_to_lt.py < "${PARM_FILE}.pair" > "${PARM_FILE}.pair.lt"
 
142
amberparm_bond_to_lt.py < "${PARM_FILE}.bond" > "${PARM_FILE}.bond.lt"
 
143
amberparm_angle_to_lt.py < "${PARM_FILE}.angle" > "${PARM_FILE}.angle.lt"
 
144
amberparm_dihedral_to_lt.py \
 
145
     < "${PARM_FILE}.dihedral" > "${PARM_FILE}.dihedral.lt"
 
146
amberparm_improper_to_lt.py \
 
147
     < "${PARM_FILE}.improper" > "${PARM_FILE}.improper.lt"
 
148
 
 
149
echo "$2 {"
 
150
echo ""
 
151
echo "  # ----------------------------------------------------------------------"
 
152
#echo "  # This file was automatically generated by \"common/amber/amberparm2lt.sh\""
 
153
echo "  # The basic atom nomenclature and conventions are explained here:"
 
154
echo "  #   http://ambermd.org/antechamber/gaff.pdf"
 
155
echo "  # For reference, the original gaff.dat file and format documenation are here:"
 
156
echo "  #   http://ambermd.org/AmberTools-get.html"
 
157
echo "  #   http://ambermd.org/formats.html#parm.dat"
 
158
echo "  # ----------------------------------------------------------------------"
 
159
echo ""
 
160
 
 
161
cat "$PARM_FILE.mass.lt" \
 
162
    "$PARM_FILE.pair.lt" \
 
163
    "$PARM_FILE.bond.lt" \
 
164
    "$PARM_FILE.angle.lt" \
 
165
    "$PARM_FILE.dihedral.lt" \
 
166
    "$PARM_FILE.improper.lt"
 
167
 
 
168
AMBER_STYLES_INIT=$(cat <<EOF
 
169
 
 
170
  write_once("In Init") {
 
171
    # Default styles and settings for AMBER based force-fields:
 
172
    units           real
 
173
    atom_style      full
 
174
    bond_style      hybrid harmonic
 
175
    angle_style     hybrid harmonic
 
176
    dihedral_style  hybrid fourier
 
177
    improper_style  hybrid cvff
 
178
    pair_style      hybrid lj/charmm/coul/long 9.0 10.0 10.0
 
179
    kspace_style    pppm 0.0001
 
180
    # If long-range coulombic forces are not needed, replace the previous two
 
181
    # lines with "pair_style hybrid lj/charmm/coul/charmm 9.0 10.0 10.0"
 
182
    pair_modify     mix arithmetic
 
183
    special_bonds   amber
 
184
  }
 
185
EOF
 
186
)
 
187
 
 
188
echo "$AMBER_STYLES_INIT"
 
189
echo ""
 
190
echo "}"
 
191
echo ""
 
192
echo ""
 
193