# PyMOL

from pymol import cmd,stored
from chempy.champ import Champ
import re

import string

amber_elec_radius_list = [
   ["ALA","N",1.8240],
["ALA","H",0.6000],
["ALA","CA",1.9080],
["ALA","HA",1.3870],
["ALA","CB",1.9080],
["ALA","HB1",1.4870],
["ALA","HB2",1.4870],
["ALA","HB3",1.4870],
["ALA","C",1.9080],
["ALA","O",1.6612],
["ARG","N",1.8240],
["ARG","H",0.6000],
["ARG","CA",1.9080],
["ARG","HA",1.3870],
["ARG","CB",1.9080],
["ARG","HB2",1.4870],
["ARG","HB3",1.4870],
["ARG","CG",1.9080],
["ARG","HG2",1.4870],
["ARG","HG3",1.4870],
["ARG","CD",1.9080],
["ARG","HD2",1.3870],
["ARG","HD3",1.3870],
["ARG","NE",1.8240],
["ARG","HE",0.6000],
["ARG","CZ",1.9080],
["ARG","NH1",1.8240],
["ARG","HH11",0.6000],
["ARG","HH12",0.6000],
["ARG","NH2",1.8240],
["ARG","HH21",0.6000],
["ARG","HH22",0.6000],
["ARG","C",1.9080],
["ARG","O",1.6612],
["ASH","N",1.8240],
["ASH","H",0.6000],
["ASH","CA",1.9080],
["ASH","HA",1.3870],
["ASH","CB",1.9080],
["ASH","HB2",1.4870],
["ASH","HB3",1.4870],
["ASH","CG",1.9080],
["ASH","OD1",1.6612],
["ASH","OD2",1.7210],
["ASH","HD2",0.0000],
["ASH","C",1.9080],
["ASH","O",1.6612],
["ASN","N",1.8240],
["ASN","H",0.6000],
["ASN","CA",1.9080],
["ASN","HA",1.3870],
["ASN","CB",1.9080],
["ASN","HB2",1.4870],
["ASN","HB3",1.4870],
["ASN","CG",1.9080],
["ASN","OD1",1.6612],
["ASN","ND2",1.8240],
["ASN","HD21",0.6000],
["ASN","HD22",0.6000],
["ASN","C",1.9080],
["ASN","O",1.6612],
["ASP","N",1.8240],
["ASP","H",0.6000],
["ASP","CA",1.9080],
["ASP","HA",1.3870],
["ASP","CB",1.9080],
["ASP","HB2",1.4870],
["ASP","HB3",1.4870],
["ASP","CG",1.9080],
["ASP","OD1",1.6612],
["ASP","OD2",1.6612],
["ASP","C",1.9080],
["ASP","O",1.6612],
["CYM","N",1.8240],
["CYM","HN",0.6000],
["CYM","CA",1.9080],
["CYM","HA",1.3870],
["CYM","CB",1.9080],
["CYM","HB3",1.3870],
["CYM","HB2",1.3870],
["CYM","SG",2.0000],
["CYM","C",1.9080],
["CYM","O",1.6612],
["CYS","N",1.8240],
["CYS","H",0.6000],
["CYS","CA",1.9080],
["CYS","HA",1.3870],
["CYS","CB",1.9080],
["CYS","HB2",1.3870],
["CYS","HB3",1.3870],
["CYS","SG",2.0000],
["CYS","HG",0.6000],
["CYS","C",1.9080],
["CYS","O",1.6612],
["CYX","N",1.8240],
["CYX","H",0.6000],
["CYX","CA",1.9080],
["CYX","HA",1.3870],
["CYX","CB",1.9080],
["CYX","HB2",1.3870],
["CYX","HB3",1.3870],
["CYX","SG",2.0000],
["CYX","C",1.9080],
["CYX","O",1.6612],
["GLH","N",1.8240],
["GLH","H",0.6000],
["GLH","CA",1.9080],
["GLH","HA",1.3870],
["GLH","CB",1.9080],
["GLH","HB2",1.4870],
["GLH","HB3",1.4870],
["GLH","CG",1.9080],
["GLH","HG2",1.4870],
["GLH","HG3",1.4870],
["GLH","CD",1.9080],
["GLH","OE1",1.6612],
["GLH","OE2",1.7210],
["GLH","HE2",0.0000],
["GLH","C",1.9080],
["GLH","O",1.6612],
["GLN","N",1.8240],
["GLN","H",0.6000],
["GLN","CA",1.9080],
["GLN","HA",1.3870],
["GLN","CB",1.9080],
["GLN","HB2",1.4870],
["GLN","HB3",1.4870],
["GLN","CG",1.9080],
["GLN","HG2",1.4870],
["GLN","HG3",1.4870],
["GLN","CD",1.9080],
["GLN","OE1",1.6612],
["GLN","NE2",1.8240],
["GLN","HE21",0.6000],
["GLN","HE22",0.6000],
["GLN","C",1.9080],
["GLN","O",1.6612],
["GLU","N",1.8240],
["GLU","H",0.6000],
["GLU","CA",1.9080],
["GLU","HA",1.3870],
["GLU","CB",1.9080],
["GLU","HB2",1.4870],
["GLU","HB3",1.4870],
["GLU","CG",1.9080],
["GLU","HG2",1.4870],
["GLU","HG3",1.4870],
["GLU","CD",1.9080],
["GLU","OE1",1.6612],
["GLU","OE2",1.6612],
["GLU","C",1.9080],
["GLU","O",1.6612],
["GLY","N",1.8240],
["GLY","H",0.6000],
["GLY","CA",1.9080],
["GLY","HA",1.3870],
["GLY","HA3",1.3870],
["GLY","C",1.9080],
["GLY","O",1.6612],
["HID","N",1.8240],
["HID","H",0.6000],
["HID","CA",1.9080],
["HID","HA",1.3870],
["HID","CB",1.9080],
["HID","HB2",1.4870],
["HID","HB3",1.4870],
["HID","CG",1.9080],
["HID","ND1",1.8240],
["HID","HD1",0.6000],
["HID","CE1",1.9080],
["HID","HE1",1.3590],
["HID","NE2",1.8240],
["HID","CD2",1.9080],
["HID","HD2",1.4090],
["HID","C",1.9080],
["HID","O",1.6612],
["HIE","N",1.8240],
["HIE","H",0.6000],
["HIE","CA",1.9080],
["HIE","HA",1.3870],
["HIE","CB",1.9080],
["HIE","HB2",1.4870],
["HIE","HB3",1.4870],
["HIE","CG",1.9080],
["HIE","ND1",1.8240],
["HIE","CE1",1.9080],
["HIE","HE1",1.3590],
["HIE","NE2",1.8240],
["HIE","HE2",0.6000],
["HIE","CD2",1.9080],
["HIE","HD2",1.4090],
["HIE","C",1.9080],
["HIE","O",1.6612],
["HIP","N",1.8240],
["HIP","H",0.6000],
["HIP","CA",1.9080],
["HIP","HA",1.3870],
["HIP","CB",1.9080],
["HIP","HB2",1.4870],
["HIP","HB3",1.4870],
["HIP","CG",1.9080],
["HIP","ND1",1.8240],
["HIP","HD1",0.6000],
["HIP","CE1",1.9080],
["HIP","HE1",1.3590],
["HIP","NE2",1.8240],
["HIP","HE2",0.6000],
["HIP","CD2",1.9080],
["HIP","HD2",1.4090],
["HIP","C",1.9080],
["HIP","O",1.6612],
["ILE","N",1.8240],
["ILE","H",0.6000],
["ILE","CA",1.9080],
["ILE","HA",1.3870],
["ILE","CB",1.9080],
["ILE","HB",1.4870],
["ILE","CG2",1.9080],
["ILE","HG21",1.4870],
["ILE","HG22",1.4870],
["ILE","HG23",1.4870],
["ILE","CG1",1.9080],
["ILE","HG12",1.4870],
["ILE","HG13",1.4870],
["ILE","CD1",1.9080],
["ILE","HD11",1.4870],
["ILE","HD12",1.4870],
["ILE","HD13",1.4870],
["ILE","C",1.9080],
["ILE","O",1.6612],
["LEU","N",1.8240],
["LEU","H",0.6000],
["LEU","CA",1.9080],
["LEU","HA",1.3870],
["LEU","CB",1.9080],
["LEU","HB2",1.4870],
["LEU","HB3",1.4870],
["LEU","CG",1.9080],
["LEU","HG",1.4870],
["LEU","CD1",1.9080],
["LEU","HD11",1.4870],
["LEU","HD12",1.4870],
["LEU","HD13",1.4870],
["LEU","CD2",1.9080],
["LEU","HD21",1.4870],
["LEU","HD22",1.4870],
["LEU","HD23",1.4870],
["LEU","C",1.9080],
["LEU","O",1.6612],
["LYN","N",1.8240],
["LYN","H",0.6000],
["LYN","CA",1.9080],
["LYN","HA",1.3870],
["LYN","CB",1.9080],
["LYN","HB2",1.4870],
["LYN","HB3",1.4870],
["LYN","CG",1.9080],
["LYN","HG2",1.4870],
["LYN","HG3",1.4870],
["LYN","CD",1.9080],
["LYN","HD2",1.4870],
["LYN","HD3",1.4870],
["LYN","CE",1.9080],
["LYN","HE2",1.1000],
["LYN","HE3",1.1000],
["LYN","NZ",1.8240],
["LYN","HZ2",0.6000],
["LYN","HZ3",0.6000],
["LYN","C",1.9080],
["LYN","O",1.6612],
["LYS","N",1.8240],
["LYS","H",0.6000],
["LYS","CA",1.9080],
["LYS","HA",1.3870],
["LYS","CB",1.9080],
["LYS","HB2",1.4870],
["LYS","HB3",1.4870],
["LYS","CG",1.9080],
["LYS","HG2",1.4870],
["LYS","HG3",1.4870],
["LYS","CD",1.9080],
["LYS","HD2",1.4870],
["LYS","HD3",1.4870],
["LYS","CE",1.9080],
["LYS","HE2",1.1000],
["LYS","HE3",1.1000],
["LYS","NZ",1.8240],
["LYS","HZ1",0.6000],
["LYS","HZ2",0.6000],
["LYS","HZ3",0.6000],
["LYS","C",1.9080],
["LYS","O",1.6612],
["MET","N",1.8240],
["MET","H",0.6000],
["MET","CA",1.9080],
["MET","HA",1.3870],
["MET","CB",1.9080],
["MET","HB2",1.4870],
["MET","HB3",1.4870],
["MET","CG",1.9080],
["MET","HG2",1.3870],
["MET","HG3",1.3870],
["MET","SD",2.0000],
["MET","CE",1.9080],
["MET","HE1",1.3870],
["MET","HE2",1.3870],
["MET","HE3",1.3870],
["MET","C",1.9080],
["MET","O",1.6612],
["PHE","N",1.8240],
["PHE","H",0.6000],
["PHE","CA",1.9080],
["PHE","HA",1.3870],
["PHE","CB",1.9080],
["PHE","HB2",1.4870],
["PHE","HB3",1.4870],
["PHE","CG",1.9080],
["PHE","CD1",1.9080],
["PHE","HD1",1.4590],
["PHE","CE1",1.9080],
["PHE","HE1",1.4590],
["PHE","CZ",1.9080],
["PHE","HZ",1.4590],
["PHE","CE2",1.9080],
["PHE","HE2",1.4590],
["PHE","CD2",1.9080],
["PHE","HD2",1.4590],
["PHE","C",1.9080],
["PHE","O",1.6612],
["PRO","N",1.8240],
["PRO","CD",1.9080],
["PRO","HD2",1.3870],
["PRO","HD3",1.3870],
["PRO","CG",1.9080],
["PRO","HG2",1.4870],
["PRO","HG3",1.4870],
["PRO","CB",1.9080],
["PRO","HB2",1.4870],
["PRO","HB3",1.4870],
["PRO","CA",1.9080],
["PRO","HA",1.3870],
["PRO","C",1.9080],
["PRO","O",1.6612],
["SER","N",1.8240],
["SER","H",0.6000],
["SER","CA",1.9080],
["SER","HA",1.3870],
["SER","CB",1.9080],
["SER","HB2",1.3870],
["SER","HB3",1.3870],
["SER","OG",1.7210],
["SER","HG",0.0000],
["SER","C",1.9080],
["SER","O",1.6612],
["THR","N",1.8240],
["THR","H",0.6000],
["THR","CA",1.9080],
["THR","HA",1.3870],
["THR","CB",1.9080],
["THR","HB",1.3870],
["THR","CG2",1.9080],
["THR","HG21",1.4870],
["THR","HG22",1.4870],
["THR","HG23",1.4870],
["THR","OG1",1.7210],
["THR","HG1",0.0000],
["THR","C",1.9080],
["THR","O",1.6612],
["TRP","N",1.8240],
["TRP","H",0.6000],
["TRP","CA",1.9080],
["TRP","HA",1.3870],
["TRP","CB",1.9080],
["TRP","HB2",1.4870],
["TRP","HB3",1.4870],
["TRP","CG",1.9080],
["TRP","CD1",1.9080],
["TRP","HD1",1.4090],
["TRP","NE1",1.8240],
["TRP","HE1",0.6000],
["TRP","CE2",1.9080],
["TRP","CZ2",1.9080],
["TRP","HZ2",1.4590],
["TRP","CH2",1.9080],
["TRP","HH2",1.4590],
["TRP","CZ3",1.9080],
["TRP","HZ3",1.4590],
["TRP","CE3",1.9080],
["TRP","HE3",1.4590],
["TRP","CD2",1.9080],
["TRP","C",1.9080],
["TRP","O",1.6612],
["TYR","N",1.8240],
["TYR","H",0.6000],
["TYR","CA",1.9080],
["TYR","HA",1.3870],
["TYR","CB",1.9080],
["TYR","HB2",1.4870],
["TYR","HB3",1.4870],
["TYR","CG",1.9080],
["TYR","CD1",1.9080],
["TYR","HD1",1.4590],
["TYR","CE1",1.9080],
["TYR","HE1",1.4590],
["TYR","CZ",1.9080],
["TYR","OH",1.7210],
["TYR","HH",0.0000],
["TYR","CE2",1.9080],
["TYR","HE2",1.4590],
["TYR","CD2",1.9080],
["TYR","HD2",1.4590],
["TYR","C",1.9080],
["TYR","O",1.6612],
["VAL","N",1.8240],
["VAL","H",0.6000],
["VAL","CA",1.9080],
["VAL","HA",1.3870],
["VAL","CB",1.9080],
["VAL","HB",1.4870],
["VAL","CG1",1.9080],
["VAL","HG11",1.4870],
["VAL","HG12",1.4870],
["VAL","HG13",1.4870],
["VAL","CG2",1.9080],
["VAL","HG21",1.4870],
["VAL","HG22",1.4870],
["VAL","HG23",1.4870],
["VAL","C",1.9080],
["VAL","O",1.6612],
["CALA","N",1.8240],
["CALA","H",0.6000],
["CALA","CA",1.9080],
["CALA","HA",1.3870],
["CALA","CB",1.9080],
["CALA","HB1",1.4870],
["CALA","HB2",1.4870],
["CALA","HB3",1.4870],
["CALA","C",1.9080],
["CALA","O",1.6612],
["CALA","OXT",1.6612],
["CARG","N",1.8240],
["CARG","H",0.6000],
["CARG","CA",1.9080],
["CARG","HA",1.3870],
["CARG","CB",1.9080],
["CARG","HB2",1.4870],
["CARG","HB3",1.4870],
["CARG","CG",1.9080],
["CARG","HG2",1.4870],
["CARG","HG3",1.4870],
["CARG","CD",1.9080],
["CARG","HD2",1.3870],
["CARG","HD3",1.3870],
["CARG","NE",1.8240],
["CARG","HE",0.6000],
["CARG","CZ",1.9080],
["CARG","NH1",1.8240],
["CARG","HH11",0.6000],
["CARG","HH12",0.6000],
["CARG","NH2",1.8240],
["CARG","HH21",0.6000],
["CARG","HH22",0.6000],
["CARG","C",1.9080],
["CARG","O",1.6612],
["CARG","OXT",1.6612],
["CASN","N",1.8240],
["CASN","H",0.6000],
["CASN","CA",1.9080],
["CASN","HA",1.3870],
["CASN","CB",1.9080],
["CASN","HB2",1.4870],
["CASN","HB3",1.4870],
["CASN","CG",1.9080],
["CASN","OD1",1.6612],
["CASN","ND2",1.8240],
["CASN","HD21",0.6000],
["CASN","HD22",0.6000],
["CASN","C",1.9080],
["CASN","O",1.6612],
["CASN","OXT",1.6612],
["CASP","N",1.8240],
["CASP","H",0.6000],
["CASP","CA",1.9080],
["CASP","HA",1.3870],
["CASP","CB",1.9080],
["CASP","HB2",1.4870],
["CASP","HB3",1.4870],
["CASP","CG",1.9080],
["CASP","OD1",1.6612],
["CASP","OD2",1.6612],
["CASP","C",1.9080],
["CASP","O",1.6612],
["CASP","OXT",1.6612],
["CCYS","N",1.8240],
["CCYS","H",0.6000],
["CCYS","CA",1.9080],
["CCYS","HA",1.3870],
["CCYS","CB",1.9080],
["CCYS","HB2",1.3870],
["CCYS","HB3",1.3870],
["CCYS","SG",2.0000],
["CCYS","HG",0.6000],
["CCYS","C",1.9080],
["CCYS","O",1.6612],
["CCYS","OXT",1.6612],
["CCYX","N",1.8240],
["CCYX","H",0.6000],
["CCYX","CA",1.9080],
["CCYX","HA",1.3870],
["CCYX","CB",1.9080],
["CCYX","HB2",1.3870],
["CCYX","HB3",1.3870],
["CCYX","SG",2.0000],
["CCYX","C",1.9080],
["CCYX","O",1.6612],
["CCYX","OXT",1.6612],
["CGLN","N",1.8240],
["CGLN","H",0.6000],
["CGLN","CA",1.9080],
["CGLN","HA",1.3870],
["CGLN","CB",1.9080],
["CGLN","HB2",1.4870],
["CGLN","HB3",1.4870],
["CGLN","CG",1.9080],
["CGLN","HG2",1.4870],
["CGLN","HG3",1.4870],
["CGLN","CD",1.9080],
["CGLN","OE1",1.6612],
["CGLN","NE2",1.8240],
["CGLN","HE21",0.6000],
["CGLN","HE22",0.6000],
["CGLN","C",1.9080],
["CGLN","O",1.6612],
["CGLN","OXT",1.6612],
["CGLU","N",1.8240],
["CGLU","H",0.6000],
["CGLU","CA",1.9080],
["CGLU","HA",1.3870],
["CGLU","CB",1.9080],
["CGLU","HB2",1.4870],
["CGLU","HB3",1.4870],
["CGLU","CG",1.9080],
["CGLU","HG2",1.4870],
["CGLU","HG3",1.4870],
["CGLU","CD",1.9080],
["CGLU","OE1",1.6612],
["CGLU","OE2",1.6612],
["CGLU","C",1.9080],
["CGLU","O",1.6612],
["CGLU","OXT",1.6612],
["CGLY","N",1.8240],
["CGLY","H",0.6000],
["CGLY","CA",1.9080],
["CGLY","HA",1.3870],
["CGLY","HA3",1.3870],
["CGLY","C",1.9080],
["CGLY","O",1.6612],
["CGLY","OXT",1.6612],
["CHID","N",1.8240],
["CHID","H",0.6000],
["CHID","CA",1.9080],
["CHID","HA",1.3870],
["CHID","CB",1.9080],
["CHID","HB2",1.4870],
["CHID","HB3",1.4870],
["CHID","CG",1.9080],
["CHID","ND1",1.8240],
["CHID","HD1",0.6000],
["CHID","CE1",1.9080],
["CHID","HE1",1.3590],
["CHID","NE2",1.8240],
["CHID","CD2",1.9080],
["CHID","HD2",1.4090],
["CHID","C",1.9080],
["CHID","O",1.6612],
["CHID","OXT",1.6612],
["CHIE","N",1.8240],
["CHIE","H",0.6000],
["CHIE","CA",1.9080],
["CHIE","HA",1.3870],
["CHIE","CB",1.9080],
["CHIE","HB2",1.4870],
["CHIE","HB3",1.4870],
["CHIE","CG",1.9080],
["CHIE","ND1",1.8240],
["CHIE","CE1",1.9080],
["CHIE","HE1",1.3590],
["CHIE","NE2",1.8240],
["CHIE","HE2",0.6000],
["CHIE","CD2",1.9080],
["CHIE","HD2",1.4090],
["CHIE","C",1.9080],
["CHIE","O",1.6612],
["CHIE","OXT",1.6612],
["CHIP","N",1.8240],
["CHIP","H",0.6000],
["CHIP","CA",1.9080],
["CHIP","HA",1.3870],
["CHIP","CB",1.9080],
["CHIP","HB2",1.4870],
["CHIP","HB3",1.4870],
["CHIP","CG",1.9080],
["CHIP","ND1",1.8240],
["CHIP","HD1",0.6000],
["CHIP","CE1",1.9080],
["CHIP","HE1",1.3590],
["CHIP","NE2",1.8240],
["CHIP","HE2",0.6000],
["CHIP","CD2",1.9080],
["CHIP","HD2",1.4090],
["CHIP","C",1.9080],
["CHIP","O",1.6612],
["CHIP","OXT",1.6612],
["CILE","N",1.8240],
["CILE","H",0.6000],
["CILE","CA",1.9080],
["CILE","HA",1.3870],
["CILE","CB",1.9080],
["CILE","HB",1.4870],
["CILE","CG2",1.9080],
["CILE","HG21",1.4870],
["CILE","HG22",1.4870],
["CILE","HG23",1.4870],
["CILE","CG1",1.9080],
["CILE","HG12",1.4870],
["CILE","HG13",1.4870],
["CILE","CD1",1.9080],
["CILE","HD11",1.4870],
["CILE","HD12",1.4870],
["CILE","HD13",1.4870],
["CILE","C",1.9080],
["CILE","O",1.6612],
["CILE","OXT",1.6612],
["CLEU","N",1.8240],
["CLEU","H",0.6000],
["CLEU","CA",1.9080],
["CLEU","HA",1.3870],
["CLEU","CB",1.9080],
["CLEU","HB2",1.4870],
["CLEU","HB3",1.4870],
["CLEU","CG",1.9080],
["CLEU","HG",1.4870],
["CLEU","CD1",1.9080],
["CLEU","HD11",1.4870],
["CLEU","HD12",1.4870],
["CLEU","HD13",1.4870],
["CLEU","CD2",1.9080],
["CLEU","HD21",1.4870],
["CLEU","HD22",1.4870],
["CLEU","HD23",1.4870],
["CLEU","C",1.9080],
["CLEU","O",1.6612],
["CLEU","OXT",1.6612],
["CLYS","N",1.8240],
["CLYS","H",0.6000],
["CLYS","CA",1.9080],
["CLYS","HA",1.3870],
["CLYS","CB",1.9080],
["CLYS","HB2",1.4870],
["CLYS","HB3",1.4870],
["CLYS","CG",1.9080],
["CLYS","HG2",1.4870],
["CLYS","HG3",1.4870],
["CLYS","CD",1.9080],
["CLYS","HD2",1.4870],
["CLYS","HD3",1.4870],
["CLYS","CE",1.9080],
["CLYS","HE2",1.1000],
["CLYS","HE3",1.1000],
["CLYS","NZ",1.8240],
["CLYS","HZ1",0.6000],
["CLYS","HZ2",0.6000],
["CLYS","HZ3",0.6000],
["CLYS","C",1.9080],
["CLYS","O",1.6612],
["CLYS","OXT",1.6612],
["CMET","N",1.8240],
["CMET","H",0.6000],
["CMET","CA",1.9080],
["CMET","HA",1.3870],
["CMET","CB",1.9080],
["CMET","HB2",1.4870],
["CMET","HB3",1.4870],
["CMET","CG",1.9080],
["CMET","HG2",1.3870],
["CMET","HG3",1.3870],
["CMET","SD",2.0000],
["CMET","CE",1.9080],
["CMET","HE1",1.3870],
["CMET","HE2",1.3870],
["CMET","HE3",1.3870],
["CMET","C",1.9080],
["CMET","O",1.6612],
["CMET","OXT",1.6612],
["CPHE","N",1.8240],
["CPHE","H",0.6000],
["CPHE","CA",1.9080],
["CPHE","HA",1.3870],
["CPHE","CB",1.9080],
["CPHE","HB2",1.4870],
["CPHE","HB3",1.4870],
["CPHE","CG",1.9080],
["CPHE","CD1",1.9080],
["CPHE","HD1",1.4590],
["CPHE","CE1",1.9080],
["CPHE","HE1",1.4590],
["CPHE","CZ",1.9080],
["CPHE","HZ",1.4590],
["CPHE","CE2",1.9080],
["CPHE","HE2",1.4590],
["CPHE","CD2",1.9080],
["CPHE","HD2",1.4590],
["CPHE","C",1.9080],
["CPHE","O",1.6612],
["CPHE","OXT",1.6612],
["CPRO","N",1.8240],
["CPRO","CD",1.9080],
["CPRO","HD2",1.3870],
["CPRO","HD3",1.3870],
["CPRO","CG",1.9080],
["CPRO","HG2",1.4870],
["CPRO","HG3",1.4870],
["CPRO","CB",1.9080],
["CPRO","HB2",1.4870],
["CPRO","HB3",1.4870],
["CPRO","CA",1.9080],
["CPRO","HA",1.3870],
["CPRO","C",1.9080],
["CPRO","O",1.6612],
["CPRO","OXT",1.6612],
["CSER","N",1.8240],
["CSER","H",0.6000],
["CSER","CA",1.9080],
["CSER","HA",1.3870],
["CSER","CB",1.9080],
["CSER","HB2",1.3870],
["CSER","HB3",1.3870],
["CSER","OG",1.7210],
["CSER","HG",0.0000],
["CSER","C",1.9080],
["CSER","O",1.6612],
["CSER","OXT",1.6612],
["CTHR","N",1.8240],
["CTHR","H",0.6000],
["CTHR","CA",1.9080],
["CTHR","HA",1.3870],
["CTHR","CB",1.9080],
["CTHR","HB",1.3870],
["CTHR","CG2",1.9080],
["CTHR","HG21",1.4870],
["CTHR","HG22",1.4870],
["CTHR","HG23",1.4870],
["CTHR","OG1",1.7210],
["CTHR","HG1",0.0000],
["CTHR","C",1.9080],
["CTHR","O",1.6612],
["CTHR","OXT",1.6612],
["CTRP","N",1.8240],
["CTRP","H",0.6000],
["CTRP","CA",1.9080],
["CTRP","HA",1.3870],
["CTRP","CB",1.9080],
["CTRP","HB2",1.4870],
["CTRP","HB3",1.4870],
["CTRP","CG",1.9080],
["CTRP","CD1",1.9080],
["CTRP","HD1",1.4090],
["CTRP","NE1",1.8240],
["CTRP","HE1",0.6000],
["CTRP","CE2",1.9080],
["CTRP","CZ2",1.9080],
["CTRP","HZ2",1.4590],
["CTRP","CH2",1.9080],
["CTRP","HH2",1.4590],
["CTRP","CZ3",1.9080],
["CTRP","HZ3",1.4590],
["CTRP","CE3",1.9080],
["CTRP","HE3",1.4590],
["CTRP","CD2",1.9080],
["CTRP","C",1.9080],
["CTRP","O",1.6612],
["CTRP","OXT",1.6612],
["CTYR","N",1.8240],
["CTYR","H",0.6000],
["CTYR","CA",1.9080],
["CTYR","HA",1.3870],
["CTYR","CB",1.9080],
["CTYR","HB2",1.4870],
["CTYR","HB3",1.4870],
["CTYR","CG",1.9080],
["CTYR","CD1",1.9080],
["CTYR","HD1",1.4590],
["CTYR","CE1",1.9080],
["CTYR","HE1",1.4590],
["CTYR","CZ",1.9080],
["CTYR","OH",1.7210],
["CTYR","HH",0.0000],
["CTYR","CE2",1.9080],
["CTYR","HE2",1.4590],
["CTYR","CD2",1.9080],
["CTYR","HD2",1.4590],
["CTYR","C",1.9080],
["CTYR","O",1.6612],
["CTYR","OXT",1.6612],
["CVAL","N",1.8240],
["CVAL","H",0.6000],
["CVAL","CA",1.9080],
["CVAL","HA",1.3870],
["CVAL","CB",1.9080],
["CVAL","HB",1.4870],
["CVAL","CG1",1.9080],
["CVAL","HG11",1.4870],
["CVAL","HG12",1.4870],
["CVAL","HG13",1.4870],
["CVAL","CG2",1.9080],
["CVAL","HG21",1.4870],
["CVAL","HG22",1.4870],
["CVAL","HG23",1.4870],
["CVAL","C",1.9080],
["CVAL","O",1.6612],
["CVAL","OXT",1.6612],
["NHE","N",1.8240],
["NHE","HN1",0.6000],
["NHE","HN2",0.6000],
["NME","N",1.8240],
["NME","H",0.6000],
["NME","CH3",1.9080],
["NME","HH31",1.3870],
["NME","HH32",1.3870],
["NME","HH33",1.3870],
["ACE","HH31",1.4870],
["ACE","CH3",1.9080],
["ACE","HH32",1.4870],
["ACE","HH33",1.4870],
["ACE","C",1.9080],
["ACE","O",1.6612],
["NALA","N",1.8240],
["NALA","H1",0.6000],
["NALA","H2",0.6000],
["NALA","H3",0.6000],
["NALA","CA",1.9080],
["NALA","HA",1.1000],
["NALA","CB",1.9080],
["NALA","HB1",1.4870],
["NALA","HB2",1.4870],
["NALA","HB3",1.4870],
["NALA","C",1.9080],
["NALA","O",1.6612],
["NARG","N",1.8240],
["NARG","H1",0.6000],
["NARG","H2",0.6000],
["NARG","H3",0.6000],
["NARG","CA",1.9080],
["NARG","HA",1.1000],
["NARG","CB",1.9080],
["NARG","HB2",1.4870],
["NARG","HB3",1.4870],
["NARG","CG",1.9080],
["NARG","HG2",1.4870],
["NARG","HG3",1.4870],
["NARG","CD",1.9080],
["NARG","HD2",1.3870],
["NARG","HD3",1.3870],
["NARG","NE",1.8240],
["NARG","HE",0.6000],
["NARG","CZ",1.9080],
["NARG","NH1",1.8240],
["NARG","HH11",0.6000],
["NARG","HH12",0.6000],
["NARG","NH2",1.8240],
["NARG","HH21",0.6000],
["NARG","HH22",0.6000],
["NARG","C",1.9080],
["NARG","O",1.6612],
["NASN","N",1.8240],
["NASN","H1",0.6000],
["NASN","H2",0.6000],
["NASN","H3",0.6000],
["NASN","CA",1.9080],
["NASN","HA",1.1000],
["NASN","CB",1.9080],
["NASN","HB2",1.4870],
["NASN","HB3",1.4870],
["NASN","CG",1.9080],
["NASN","OD1",1.6612],
["NASN","ND2",1.8240],
["NASN","HD21",0.6000],
["NASN","HD22",0.6000],
["NASN","C",1.9080],
["NASN","O",1.6612],
["NASP","N",1.8240],
["NASP","H1",0.6000],
["NASP","H2",0.6000],
["NASP","H3",0.6000],
["NASP","CA",1.9080],
["NASP","HA",1.1000],
["NASP","CB",1.9080],
["NASP","HB2",1.4870],
["NASP","HB3",1.4870],
["NASP","CG",1.9080],
["NASP","OD1",1.6612],
["NASP","OD2",1.6612],
["NASP","C",1.9080],
["NASP","O",1.6612],
["NCYS","N",1.8240],
["NCYS","H1",0.6000],
["NCYS","H2",0.6000],
["NCYS","H3",0.6000],
["NCYS","CA",1.9080],
["NCYS","HA",1.1000],
["NCYS","CB",1.9080],
["NCYS","HB2",1.3870],
["NCYS","HB3",1.3870],
["NCYS","SG",2.0000],
["NCYS","HG",0.6000],
["NCYS","C",1.9080],
["NCYS","O",1.6612],
["NCYX","N",1.8240],
["NCYX","H1",0.6000],
["NCYX","H2",0.6000],
["NCYX","H3",0.6000],
["NCYX","CA",1.9080],
["NCYX","HA",1.1000],
["NCYX","CB",1.9080],
["NCYX","HB2",1.3870],
["NCYX","HB3",1.3870],
["NCYX","SG",2.0000],
["NCYX","C",1.9080],
["NCYX","O",1.6612],
["NGLN","N",1.8240],
["NGLN","H1",0.6000],
["NGLN","H2",0.6000],
["NGLN","H3",0.6000],
["NGLN","CA",1.9080],
["NGLN","HA",1.1000],
["NGLN","CB",1.9080],
["NGLN","HB2",1.4870],
["NGLN","HB3",1.4870],
["NGLN","CG",1.9080],
["NGLN","HG2",1.4870],
["NGLN","HG3",1.4870],
["NGLN","CD",1.9080],
["NGLN","OE1",1.6612],
["NGLN","NE2",1.8240],
["NGLN","HE21",0.6000],
["NGLN","HE22",0.6000],
["NGLN","C",1.9080],
["NGLN","O",1.6612],
["NGLU","N",1.8240],
["NGLU","H1",0.6000],
["NGLU","H2",0.6000],
["NGLU","H3",0.6000],
["NGLU","CA",1.9080],
["NGLU","HA",1.1000],
["NGLU","CB",1.9080],
["NGLU","HB2",1.4870],
["NGLU","HB3",1.4870],
["NGLU","CG",1.9080],
["NGLU","HG2",1.4870],
["NGLU","HG3",1.4870],
["NGLU","CD",1.9080],
["NGLU","OE1",1.6612],
["NGLU","OE2",1.6612],
["NGLU","C",1.9080],
["NGLU","O",1.6612],
["NGLY","N",1.8240],
["NGLY","H1",0.6000],
["NGLY","H2",0.6000],
["NGLY","H3",0.6000],
["NGLY","CA",1.9080],
["NGLY","HA",1.1000],
["NGLY","HA3",1.1000],
["NGLY","C",1.9080],
["NGLY","O",1.6612],
["NHID","N",1.8240],
["NHID","H1",0.6000],
["NHID","H2",0.6000],
["NHID","H3",0.6000],
["NHID","CA",1.9080],
["NHID","HA",1.1000],
["NHID","CB",1.9080],
["NHID","HB2",1.4870],
["NHID","HB3",1.4870],
["NHID","CG",1.9080],
["NHID","ND1",1.8240],
["NHID","HD1",0.6000],
["NHID","CE1",1.9080],
["NHID","HE1",1.3590],
["NHID","NE2",1.8240],
["NHID","CD2",1.9080],
["NHID","HD2",1.4090],
["NHID","C",1.9080],
["NHID","O",1.6612],
["NHIE","N",1.8240],
["NHIE","H1",0.6000],
["NHIE","H2",0.6000],
["NHIE","H3",0.6000],
["NHIE","CA",1.9080],
["NHIE","HA",1.1000],
["NHIE","CB",1.9080],
["NHIE","HB2",1.4870],
["NHIE","HB3",1.4870],
["NHIE","CG",1.9080],
["NHIE","ND1",1.8240],
["NHIE","CE1",1.9080],
["NHIE","HE1",1.3590],
["NHIE","NE2",1.8240],
["NHIE","HE2",0.6000],
["NHIE","CD2",1.9080],
["NHIE","HD2",1.4090],
["NHIE","C",1.9080],
["NHIE","O",1.6612],
["NHIP","N",1.8240],
["NHIP","H1",0.6000],
["NHIP","H2",0.6000],
["NHIP","H3",0.6000],
["NHIP","CA",1.9080],
["NHIP","HA",1.1000],
["NHIP","CB",1.9080],
["NHIP","HB2",1.4870],
["NHIP","HB3",1.4870],
["NHIP","CG",1.9080],
["NHIP","ND1",1.8240],
["NHIP","HD1",0.6000],
["NHIP","CE1",1.9080],
["NHIP","HE1",1.3590],
["NHIP","NE2",1.8240],
["NHIP","HE2",0.6000],
["NHIP","CD2",1.9080],
["NHIP","HD2",1.4090],
["NHIP","C",1.9080],
["NHIP","O",1.6612],
["NILE","N",1.8240],
["NILE","H1",0.6000],
["NILE","H2",0.6000],
["NILE","H3",0.6000],
["NILE","CA",1.9080],
["NILE","HA",1.1000],
["NILE","CB",1.9080],
["NILE","HB",1.4870],
["NILE","CG2",1.9080],
["NILE","HG21",1.4870],
["NILE","HG22",1.4870],
["NILE","HG23",1.4870],
["NILE","CG1",1.9080],
["NILE","HG12",1.4870],
["NILE","HG13",1.4870],
["NILE","CD1",1.9080],
["NILE","HD11",1.4870],
["NILE","HD12",1.4870],
["NILE","HD13",1.4870],
["NILE","C",1.9080],
["NILE","O",1.6612],
["NLEU","N",1.8240],
["NLEU","H1",0.6000],
["NLEU","H2",0.6000],
["NLEU","H3",0.6000],
["NLEU","CA",1.9080],
["NLEU","HA",1.1000],
["NLEU","CB",1.9080],
["NLEU","HB2",1.4870],
["NLEU","HB3",1.4870],
["NLEU","CG",1.9080],
["NLEU","HG",1.4870],
["NLEU","CD1",1.9080],
["NLEU","HD11",1.4870],
["NLEU","HD12",1.4870],
["NLEU","HD13",1.4870],
["NLEU","CD2",1.9080],
["NLEU","HD21",1.4870],
["NLEU","HD22",1.4870],
["NLEU","HD23",1.4870],
["NLEU","C",1.9080],
["NLEU","O",1.6612],
["NLYS","N",1.8240],
["NLYS","H1",0.6000],
["NLYS","H2",0.6000],
["NLYS","H3",0.6000],
["NLYS","CA",1.9080],
["NLYS","HA",1.1000],
["NLYS","CB",1.9080],
["NLYS","HB2",1.4870],
["NLYS","HB3",1.4870],
["NLYS","CG",1.9080],
["NLYS","HG2",1.4870],
["NLYS","HG3",1.4870],
["NLYS","CD",1.9080],
["NLYS","HD2",1.4870],
["NLYS","HD3",1.4870],
["NLYS","CE",1.9080],
["NLYS","HE2",1.1000],
["NLYS","HE3",1.1000],
["NLYS","NZ",1.8240],
["NLYS","HZ1",0.6000],
["NLYS","HZ2",0.6000],
["NLYS","HZ3",0.6000],
["NLYS","C",1.9080],
["NLYS","O",1.6612],
["NMET","N",1.8240],
["NMET","H1",0.6000],
["NMET","H2",0.6000],
["NMET","H3",0.6000],
["NMET","CA",1.9080],
["NMET","HA",1.1000],
["NMET","CB",1.9080],
["NMET","HB2",1.4870],
["NMET","HB3",1.4870],
["NMET","CG",1.9080],
["NMET","HG2",1.3870],
["NMET","HG3",1.3870],
["NMET","SD",2.0000],
["NMET","CE",1.9080],
["NMET","HE1",1.3870],
["NMET","HE2",1.3870],
["NMET","HE3",1.3870],
["NMET","C",1.9080],
["NMET","O",1.6612],
["NPHE","N",1.8240],
["NPHE","H1",0.6000],
["NPHE","H2",0.6000],
["NPHE","H3",0.6000],
["NPHE","CA",1.9080],
["NPHE","HA",1.1000],
["NPHE","CB",1.9080],
["NPHE","HB2",1.4870],
["NPHE","HB3",1.4870],
["NPHE","CG",1.9080],
["NPHE","CD1",1.9080],
["NPHE","HD1",1.4590],
["NPHE","CE1",1.9080],
["NPHE","HE1",1.4590],
["NPHE","CZ",1.9080],
["NPHE","HZ",1.4590],
["NPHE","CE2",1.9080],
["NPHE","HE2",1.4590],
["NPHE","CD2",1.9080],
["NPHE","HD2",1.4590],
["NPHE","C",1.9080],
["NPHE","O",1.6612],
["NPRO","N",1.8240],
["NPRO","H2",0.6000],
["NPRO","H3",0.6000],
["NPRO","CD",1.9080],
["NPRO","HD2",1.1000],
["NPRO","HD3",1.1000],
["NPRO","CG",1.9080],
["NPRO","HG2",1.4870],
["NPRO","HG3",1.4870],
["NPRO","CB",1.9080],
["NPRO","HB2",1.4870],
["NPRO","HB3",1.4870],
["NPRO","CA",1.9080],
["NPRO","HA",1.1000],
["NPRO","C",1.9080],
["NPRO","O",1.6612],
["NSER","N",1.8240],
["NSER","H1",0.6000],
["NSER","H2",0.6000],
["NSER","H3",0.6000],
["NSER","CA",1.9080],
["NSER","HA",1.1000],
["NSER","CB",1.9080],
["NSER","HB2",1.3870],
["NSER","HB3",1.3870],
["NSER","OG",1.7210],
["NSER","HG",0.0000],
["NSER","C",1.9080],
["NSER","O",1.6612],
["NTHR","N",1.8240],
["NTHR","H1",0.6000],
["NTHR","H2",0.6000],
["NTHR","H3",0.6000],
["NTHR","CA",1.9080],
["NTHR","HA",1.1000],
["NTHR","CB",1.9080],
["NTHR","HB",1.3870],
["NTHR","CG2",1.9080],
["NTHR","HG21",1.4870],
["NTHR","HG22",1.4870],
["NTHR","HG23",1.4870],
["NTHR","OG1",1.7210],
["NTHR","HG1",0.0000],
["NTHR","C",1.9080],
["NTHR","O",1.6612],
["NTRP","N",1.8240],
["NTRP","H1",0.6000],
["NTRP","H2",0.6000],
["NTRP","H3",0.6000],
["NTRP","CA",1.9080],
["NTRP","HA",1.1000],
["NTRP","CB",1.9080],
["NTRP","HB2",1.4870],
["NTRP","HB3",1.4870],
["NTRP","CG",1.9080],
["NTRP","CD1",1.9080],
["NTRP","HD1",1.4090],
["NTRP","NE1",1.8240],
["NTRP","HE1",0.6000],
["NTRP","CE2",1.9080],
["NTRP","CZ2",1.9080],
["NTRP","HZ2",1.4590],
["NTRP","CH2",1.9080],
["NTRP","HH2",1.4590],
["NTRP","CZ3",1.9080],
["NTRP","HZ3",1.4590],
["NTRP","CE3",1.9080],
["NTRP","HE3",1.4590],
["NTRP","CD2",1.9080],
["NTRP","C",1.9080],
["NTRP","O",1.6612],
["NTYR","N",1.8240],
["NTYR","H1",0.6000],
["NTYR","H2",0.6000],
["NTYR","H3",0.6000],
["NTYR","CA",1.9080],
["NTYR","HA",1.1000],
["NTYR","CB",1.9080],
["NTYR","HB2",1.4870],
["NTYR","HB3",1.4870],
["NTYR","CG",1.9080],
["NTYR","CD1",1.9080],
["NTYR","HD1",1.4590],
["NTYR","CE1",1.9080],
["NTYR","HE1",1.4590],
["NTYR","CZ",1.9080],
["NTYR","OH",1.7210],
["NTYR","HH",0.0000],
["NTYR","CE2",1.9080],
["NTYR","HE2",1.4590],
["NTYR","CD2",1.9080],
["NTYR","HD2",1.4590],
["NTYR","C",1.9080],
["NTYR","O",1.6612],
["NVAL","N",1.8240],
["NVAL","H1",0.6000],
["NVAL","H2",0.6000],
["NVAL","H3",0.6000],
["NVAL","CA",1.9080],
["NVAL","HA",1.1000],
["NVAL","CB",1.9080],
["NVAL","HB",1.4870],
["NVAL","CG1",1.9080],
["NVAL","HG11",1.4870],
["NVAL","HG12",1.4870],
["NVAL","HG13",1.4870],
["NVAL","CG2",1.9080],
["NVAL","HG21",1.4870],
["NVAL","HG22",1.4870],
["NVAL","HG23",1.4870],
["NVAL","C",1.9080],
["NVAL","O",1.6612],
["WAT","HW",0.0000],
["WAT","OW",1.6612],
]

amber_elec_radius_dict = {}

for a in amber_elec_radius_list:
   res_key = string.lower(a[0])
   res = a[0]
   atom = a[1]
   if len(res)==4:
      if res[0]=="N":
         res_key = "nt_"+string.lower(res[1:4])      
      elif res[0]=="C":
         res_key = "ct_"+string.lower(res[1:4])
   key = (res_key,atom)
   amber_elec_radius_dict[key]=a[2]
   if res_key[-3:] =='hie':
      key = (res_key[:-3]+'his',atom)
      amber_elec_radius_dict[key]=a[2]
   
print '''# NOTE: This file was autogenerated
amber99_dict = {
'''

for grp in (  'ala','arg','asp','asn','cys','gln','glu','gly','his',
              'hip','hie','hid','ile','leu','lys','met','phe','pro',
              'ser','thr','trp','tyr','val' ):

   stored.fc_dict = {}
   print "'"+string.upper(grp)+"': ["

   for res in ( grp,"nt_"+grp,"ct_"+grp):
      ch = Champ()
      print "   ("
      if grp=='wat' and len(res)>3:
         continue
      cmd.fragment(res,"tmp")
      stored.pc_dict = {}
      stored.at_dict = {}
      cmd.iterate("tmp","stored.pc_dict[name]=partial_charge;stored.at_dict[name]=text_type",quiet=1)
      if res[0:3]=="ct_":
         cmd.alter("name OXT","formal_charge=-1")
      elif res[0:3]=="nt_":
         cmd.alter("name N","formal_charge=1")
      # some PyMOL fragments are missing formal charges...
      cmd.alter("GLU/OE2|ASP/OD2","formal_charge=-1")
      cmd.alter("HIP/ND1|ARG/NH1|LYS/NZ","formal_charge=1")
      model = cmd.get_model("tmp")
      cmd.delete("tmp")

      m1 = ch.insert_model(model)
      ch.pattern_detect_chirality(m1)
      ch.pattern_orient_bonds(m1)
      pat1 = ch.pattern_get_string_with_names(m1)
      ch.pattern_detect_chirality(m1)
      pat2 = ch.pattern_get_string_with_names(m1)

   # confirm that CHAMP handles this pattern well...

      if pat1!=pat2:
         print " Chirality Assignment Error!"
         print pat1
         print pat2
         break
      else:
         pat = pat1

#      print pat1

      clean_pat = re.sub("<[^>]*>","",pat)
      source = ch.insert_pattern_string(clean_pat)
   #   print ch.pattern_get_string(source)
   #   print ch.pattern_get_string(m1)
      if ch.match_1v1_b(source,m1)==0:
         print " Error: Pattern doesn't match with self!"

      pat_isomer = string.replace(pat,"@@","X")
      pat_isomer = string.replace(pat_isomer,"@","@@")
      pat_isomer = string.replace(pat_isomer,"X","@")
      isomer = ch.insert_pattern_string(pat_isomer)
      if ch.match_1v1_b(isomer,m1)==1:
         if(grp!='gly'):
            print " Error: Pattern matches the enatiomer"

      pat_racemic = string.replace(pat,"@","")
      racemic = ch.insert_pattern_string(pat_racemic)

   #   print ch.pattern_get_string(source)
   #   print ch.pattern_get_string(isomer)
   #   print ch.pattern_get_string(racemic)

      if ch.match_1v1_b(racemic,source)!=1:
         print " Error: Racemic doesn't match source isomer"

      if ch.match_1v1_b(racemic,isomer)!=1:
         print " Error: Racemic doesn't match enantiomer"

      lst = []
      for a in string.split(pat,'<'):
         for b in string.split(a,'>'):
            lst.append(b)

      tag_count = 0
      pat_list = []
      tag_list = []
      flag = 0
      while 1:
         if lst==[]:
            break
         pat_list.append(lst.pop(0))
         if lst==[]:
            break;
         nam = lst.pop(0)
         if nam[0] in ('0','1','2','3','4','5','6','7','8','9'):
            name = nam[1:]+nam[0]
         else:
            name = nam

         if res[0:3]=="nt_":
            if name=="HT1":
               name = "H1"
            elif name=="HT2":
               name = "H2"
            elif name=="HT3":
               name = "H3"
         tag_list.append((tag_count,"'"+name+"'","'"+stored.at_dict[nam]+"'",
                          stored.pc_dict[nam],amber_elec_radius_dict[(res,name)]))
         pat_list.append("<%d>"%tag_count)
         tag_count = tag_count+1

      new_pat = string.join(pat_list,'')
      print "      '"+new_pat+"',"

   #   np = ch.insert_pattern_string(new_pat)
   #   print ch.pattern_get_tags(np)
   #   ch.pattern_clear_tags(m1)
   #   print ch.match_1v1_map(np,m1,1,1)
   #   print ch.pattern_get_ext_indices_with_tags(m1)

      print "      {"
      for a in tag_list:
         print "        %2d: (%-6s, %-6s, %9.4f, %9.4f),"%a
      print "      },"
      print "   ),"
   print "],"

print "}"

   
   

   
