def extract_energies_qm(root, descriptors, molecules, angles_to_measure):
    for b in descriptors:
        for m in molecules:
            energies, angles = {}, {}
            shifts = angles_to_measure[molecules.index(m)]
            formatting = dict(root=root,
                              basis=b,
                              mol=m)
            for a in range(0,360,5):
                formatting['angle2'] = a
                if a == 180:
                    a = 179
                formatting['angle'] = a
                if (not os.path.isfile('{root}/{basis}/{mol}/{mol}.{angle:03}.log'.format(**formatting)) 
                    and not os.path.isfile('{root}/{basis}/{mol}/{mol}.{angle2:03}.log'.format(**formatting))):
                    continue
                try:
                    with open('{root}/{basis}/{mol}/{mol}.{angle:03}.log'.format(**formatting),'r') as fh:
                        file = fh.readlines()
                except FileNotFoundError:
                    with open('{root}/{basis}/{mol}/{mol}.{angle2:03}.log'.format(**formatting),'r') as fh:
                        file = fh.readlines()
                conf = extract_conformation(file)
                if conf is None:
                    continue                
                energies[a] = extract_energy(file)
                angles[a] = dihedral_angle(conf[shifts[0]]['vec'],conf[shifts[1]]['vec'],
                                           conf[shifts[2]]['vec'],conf[shifts[3]]['vec'], scale='deg')
            if not energies:
                print('Nothing extracted for {basis}:{mol}'.format(**formatting))
                continue
            try:
                z_energy = energies[0]
            except KeyError:
                continue
            for i in energies:
                energies[i] -= z_energy
            
            with open('{root}/{basis}/{mol}/energies.qm.txt'.format(**formatting),'w') as fh:
                yaml.dump([energies,angles],fh)
            with open('{root}/{basis}/{mol}/fitted_curve.qm.txt'.format(**formatting),'w') as fh:
                yaml.dump(two_pass_lls(energies, angles, 3, phase=False), fh)
            with open('{root}/{basis}/{mol}/phased_fitted_curve.qm.txt'.format(**formatting),'w') as fh:
                yaml.dump(two_pass_lls(energies, angles, 3, phase=[0,90]), fh)
            with open('{root}/{basis}/{mol}/onepass_fitted_curve.qm.txt'.format(**formatting),'w') as fh:
                yaml.dump(one_pass_lls(energies, angles, phase=False), fh)
            with open('{root}/{basis}/{mol}/onepass_phased_fitted_curve.qm.txt'.format(**formatting),'w') as fh:
                yaml.dump(one_pass_lls(energies, angles, phase=[0,90]), fh)
Example #2
0
def extract_energies_qm(sets, molecules, root, angles_to_measure):
    for b in sets:
        for m in molecules:
            energies, angles = {}, {}
            shifts = angles_to_measure[molecules.index(m)]
            formatting = dict(root=root,
                              basis=b,
                              mol=m)
            for a in range(0,360,5):
                if a == 180:
                    a = 179
                formatting['angle'] = a
                if not os.path.isfile('{root}/{basis}/{mol}/{mol}.{angle:03}.log'.format(**formatting)):
                    continue
                with open('{root}/{basis}/{mol}/{mol}.{angle:03}.log'.format(**formatting),'r') as fh:
                    file = fh.readlines()
                conf = extract_conformation(file)
                if conf is None:
                    continue                
                energies[a] = extract_energy(file)
                angles[a] = dihedral_angle(conf[shifts[0]]['vec'],conf[shifts[1]]['vec'],
                                           conf[shifts[2]]['vec'],conf[shifts[3]]['vec'], scale='deg')
            if not energies:
                print('Nothing extracted for {basis}:{mol}'.format(**formatting))
                continue
            try:
                z_energy = energies[0]
            except KeyError:
                continue
            for i in energies:
                energies[i] -= z_energy
            
            with open('{root}/{basis}/{mol}/energies.txt'.format(**formatting),'w') as fh:
                yaml.dump([energies,angles],fh)
            with open('{root}/{basis}/{mol}/fitted_curve.txt'.format(**formatting),'w') as fh:
                yaml.dump(two_pass_lls(energies, angles, 3, phase=False), fh)
            with open('{root}/{basis}/{mol}/phased_fitted_curve.txt'.format(**formatting),'w') as fh:
                yaml.dump(two_pass_lls(energies, angles, 3, phase=[0,90]), fh)
def run_md_jobs(root, mols, descrips):
    molecules = {
                 'AMINO-1': {'rigid':{'aa':[16,13,7,9],
                                     'ua':[8,7,5,6],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'G564',
                            },
                 'AMINO0': {'rigid':{'aa':[2,5,8,13],
                                     'ua':[1,2,3,8],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'N0GW',
                            },
                 'AMINO1': {'rigid':{'aa':[2,5,8,16],
                                     'ua':[1,2,3,8],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'SHJ0',
                            },
                 'AMINO2': {'rigid':{'aa':[7,10,12,15],
                                     'ua':[5,6,7,8],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'6AT1',
                            },
                 'CHLORO-1': {'rigid':{'aa':[2,5,8,14],
                                     'ua':[1,2,3,6],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'PCRN',
                            },
                 'CHLORO0': {'rigid':{'aa':[2,5,8,11],
                                     'ua':[1,2,3,5],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'682F',
                            },
                 'CHLORO1': {'rigid':{'aa':[2,5,8,14],
                                     'ua':[1,2,3,6],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'ZB0H',
                            },
                 'CHLORO2': {'rigid':{'aa':[10,8,17,20],
                                     'ua':[5,4,7,8],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'35MG',
                            },
                 'HYDRO-1': {'rigid':{'aa':[15,12,6,8],
                                     'ua':[7,6,4,5],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'H5JT',
                            },
                 'HYDRO0': {'rigid':{'aa':[2,5,8,12],
                                     'ua':[1,2,3,7],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'G096',
                            },
                 'HYDRO1': {'rigid':{'aa':[2,5,8,15],
                                     'ua':[1,2,3,7],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'W6KL',
                            },
                 'HYDRO2': {'rigid':{'aa':[2,5,8,10],
                                     'ua':[1,2,3,4],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'5KRK',
                            },
                 'METH-1': {'rigid':{'aa':[2,5,8,14],
                                     'ua':[1,2,3,5],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'G011',
                            },
                 'METH0': {'rigid':{'aa':[2,5,8,14],
                                     'ua':[1,2,3,5],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'G011',
                            },
                 'METH1': {'rigid':{'aa':[2,5,8,10],
                                     'ua':[1,2,3,4],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'4MUW',
                            },
                 'METH2': {'rigid':{'aa':[2,5,8,10],
                                     'ua':[1,2,3,4],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'YE4E',
                            },
                 'THIO-1': {'rigid':{'aa':[2,5,8,15],
                                     'ua':[1,2,3,7],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'ZK6W',
                            },
                 'THIO0': {'rigid':{'aa':[2,5,8,12],
                                     'ua':[1,2,3,7],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'1QIU',
                            },
                 'THIO1': {'rigid':{'aa':[2,5,8,15],
                                     'ua':[1,2,3,7],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'5G2Q',
                            },
                 'THIO2': {'rigid':{'aa':[6,9,18,21],
                                     'ua':[4,5,8,9],
                                     'gamess':[2,1,8,9],
                                     },
                            'name':'PJLY',
                            },
                 }
    descriptors = {'Original': ['rigid']}
    #'AMINO-1'  : {'gamess':[2,1,8,9], 'aa' : [16,13,7,9], 'ua' : [8,7,5,6], }
    #for m in sorted(molecules):
    #    print("'{}' : {},".format(m, molecules[m]['rigid']))
    #return
    with open(root + '/Parameters/Templates/dihedral.template','r') as fh:
        imd_temp_1 = fh.read()
    with open(root + '/Parameters/Templates/dihedral2.template','r') as fh:
        imd_temp_2 = fh.read()
    with open(root + '/Parameters/Templates/dihedral3.template','r') as fh:
        imd_temp_3 = fh.read()
    with open(root + '/Parameters/Templates/dihedral_constraint.template','r') as fh:
        constraint_temp = fh.read()
    
    for m in mols:
        
        forms = dict(mol=m, root=root)
        aa_mtb = inlib.gromos_mtb_parse(genlib.load_file('{root}/Parameters/{mol}/{mol}.aa.mtb'.format(**forms)))
        ua_mtb = inlib.gromos_mtb_parse(genlib.load_file('{root}/Parameters/{mol}/{mol}.ua.mtb'.format(**forms)))
        
        aa_work_mol = storage.Molecule(molecules[m]['name'], mtb=aa_mtb)
        ua_work_mol = storage.Molecule(molecules[m]['name'], mtb=ua_mtb)
        
        for d in descrips:
            forms['des'] = d
            forms['outdir'] = '{root}/{des}/{mol}/MD_data'.format(**forms)
            forms['name'] = molecules[m]['name']
            if not os.path.exists('{outdir}'.format(**forms)):
                os.makedirs('{outdir}'.format(**forms))
            with open('{outdir}/{mol}.aa.1.imd'.format(**forms),'w') as fh:
                fh.write(imd_temp_1.format(**{'numberOfAtoms':aa_work_mol.atom_count}))
            with open('{outdir}/{mol}.ua.1.imd'.format(**forms),'w') as fh:
                fh.write(imd_temp_1.format(**{'numberOfAtoms':ua_work_mol.atom_count}))
            with open('{outdir}/{mol}.aa.2.imd'.format(**forms),'w') as fh:
                fh.write(imd_temp_2.format(**{'numberOfAtoms':aa_work_mol.atom_count}))
            with open('{outdir}/{mol}.ua.2.imd'.format(**forms),'w') as fh:
                fh.write(imd_temp_2.format(**{'numberOfAtoms':ua_work_mol.atom_count}))
            with open('{outdir}/{mol}.aa.3.imd'.format(**forms),'w') as fh:
                fh.write(imd_temp_3.format(**{'numberOfAtoms':aa_work_mol.atom_count}))
            with open('{outdir}/{mol}.ua.3.imd'.format(**forms),'w') as fh:
                fh.write(imd_temp_3.format(**{'numberOfAtoms':ua_work_mol.atom_count}))
                
                
            os.chdir('{root}'.format(**forms))
            
            os.system(('/usr/local/gromos++/bin/make_top @build Parameters/{mol}/{mol}.aa.mtb Parameters/54A7.mtb '
                       '@param Parameters/54A7.ifp @seq {name} @solv H2O > {outdir}/{mol}.aa.top'.format(**forms)))
            os.system(('/usr/local/gromos++/bin/make_top @build Parameters/{mol}/{mol}.ua.mtb Parameters/54A7.mtb '
                       '@param Parameters/54A7.ifp @seq {name} @solv H2O > {outdir}/{mol}.ua.top'.format(**forms)))
            
            for a in range(0,360,5):
                skip_angle = False
                forms['ang2'] = a
                if a == 180:
                    a = 179
                forms['ang'] = a
                try:
                    with open('{root}/{des}/{mol}/{mol}.{ang:03}.log'.format(**forms), 'r') as fh:
                        gamess = extract_conformation(fh.readlines(), scale=1, key='name', optimised=False)
                except FileNotFoundError:
                    with open('{root}/{des}/{mol}/{mol}.{ang2:03}.log'.format(**forms), 'r') as fh:
                        gamess = extract_conformation(fh.readlines(), scale=1, key='name', optimised=False)     
                for atm in aa_work_mol.atoms:
                    try:
                        atm.xyz = gamess[atm.atm_name.upper()]['vec']
                    except TypeError:
                        print('TypeError', atm.atm_name, d, m, a)
                        skip_angle = True
                        break
                    except KeyError:
                        print('KeyError', atm.atm_name, d, m, a)
                        raise
                if skip_angle:
                    continue
                for atm in ua_work_mol.atoms:
                    atm.xyz = gamess[atm.atm_name.upper()]['vec']
                with open('{outdir}/{mol}.{ang:03}.aa.cnf'.format(**forms), 'w') as fh:
                    fh.write(outlib.print_gromos_cnf(aa_work_mol))
                with open('{outdir}/{mol}.{ang:03}.ua.cnf'.format(**forms), 'w') as fh:
                    fh.write(outlib.print_gromos_cnf(ua_work_mol))
                #with open('{outdir}/{mol}.{ang:03}.aa.pdb'.format(**forms), 'w') as fh:
                #    fh.write(outlib.print_pdb(aa_work_mol))
                #with open('{outdir}/{mol}.{ang:03}.ua.pdb'.format(**forms), 'w') as fh:
                #    fh.write(outlib.print_pdb(ua_work_mol))
                angs_aa, angs_ua = [], []
                for des in descriptors[d]:
                    atm_a = aa_work_mol.atom(molecules[m][des]['aa'][0]).xyz
                    atm_b = aa_work_mol.atom(molecules[m][des]['aa'][1]).xyz
                    atm_c = aa_work_mol.atom(molecules[m][des]['aa'][2]).xyz
                    atm_d = aa_work_mol.atom(molecules[m][des]['aa'][3]).xyz
                    ang = dihedral_angle(atm_a,atm_b,atm_c,atm_d,scale='deg')
                    angs_aa.append('   {1}  {2}  {3}  {4}  1.0  {0:.3f}  0.0   0.0001'.format(ang, *molecules[m][des]['aa']))
                    angs_ua.append('   {1}  {2}  {3}  {4}  1.0  {0:.3f}  0.0   0.0001'.format(ang, *molecules[m][des]['ua']))
                with open('{outdir}/{mol}.{ang:03}.aa.constraints.dat'.format(**forms), 'w') as fh:
                    fh.write(constraint_temp.format(**{'constraints':'\n'.join(angs_aa)}))
                with open('{outdir}/{mol}.{ang:03}.ua.constraints.dat'.format(**forms), 'w') as fh:
                    fh.write(constraint_temp.format(**{'constraints':'\n'.join(angs_ua)}))
                # first pass
                os.system(('/opt/local/gromosXX-1773/bin/md @topo {outdir}/{mol}.aa.top @conf {outdir}/{mol}.{ang:03}.aa.cnf '
                           '@input {outdir}/{mol}.aa.1.imd @fin {outdir}/{mol}.{ang:03}.aa.min.1.cnf @develop '
                           '@dihrest {outdir}/{mol}.{ang:03}.aa.constraints.dat > {outdir}/{mol}.{ang:03}.aa.1.log'.format(**forms) ))
                
                os.system(('/opt/local/gromosXX-1773/bin/md @topo {outdir}/{mol}.ua.top @conf {outdir}/{mol}.{ang:03}.ua.cnf '
                           '@input {outdir}/{mol}.ua.1.imd @fin {outdir}/{mol}.{ang:03}.ua.min.1.cnf @develop '
                           '@dihrest {outdir}/{mol}.{ang:03}.ua.constraints.dat > {outdir}/{mol}.{ang:03}.ua.1.log'.format(**forms) ))
Example #4
0
def run_md_jobs(root, mols, descrips):
    molecules = {
        'AMINO-1': {
            'rigid': {
                'aa': [16, 13, 7, 9],
                'ua': [8, 7, 5, 6],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'G564',
        },
        'AMINO0': {
            'rigid': {
                'aa': [2, 5, 8, 13],
                'ua': [1, 2, 3, 8],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'N0GW',
        },
        'AMINO1': {
            'rigid': {
                'aa': [2, 5, 8, 16],
                'ua': [1, 2, 3, 8],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'SHJ0',
        },
        'AMINO2': {
            'rigid': {
                'aa': [7, 10, 12, 15],
                'ua': [5, 6, 7, 8],
                'gamess': [2, 1, 8, 9],
            },
            'name': '6AT1',
        },
        'CHLORO-1': {
            'rigid': {
                'aa': [2, 5, 8, 14],
                'ua': [1, 2, 3, 6],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'PCRN',
        },
        'CHLORO0': {
            'rigid': {
                'aa': [2, 5, 8, 11],
                'ua': [1, 2, 3, 5],
                'gamess': [2, 1, 8, 9],
            },
            'name': '682F',
        },
        'CHLORO1': {
            'rigid': {
                'aa': [2, 5, 8, 14],
                'ua': [1, 2, 3, 6],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'ZB0H',
        },
        'CHLORO2': {
            'rigid': {
                'aa': [10, 8, 17, 20],
                'ua': [5, 4, 7, 8],
                'gamess': [2, 1, 8, 9],
            },
            'name': '35MG',
        },
        'HYDRO-1': {
            'rigid': {
                'aa': [15, 12, 6, 8],
                'ua': [7, 6, 4, 5],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'H5JT',
        },
        'HYDRO0': {
            'rigid': {
                'aa': [2, 5, 8, 12],
                'ua': [1, 2, 3, 7],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'G096',
        },
        'HYDRO1': {
            'rigid': {
                'aa': [2, 5, 8, 15],
                'ua': [1, 2, 3, 7],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'W6KL',
        },
        'HYDRO2': {
            'rigid': {
                'aa': [2, 5, 8, 10],
                'ua': [1, 2, 3, 4],
                'gamess': [2, 1, 8, 9],
            },
            'name': '5KRK',
        },
        'METH-1': {
            'rigid': {
                'aa': [2, 5, 8, 14],
                'ua': [1, 2, 3, 5],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'G011',
        },
        'METH0': {
            'rigid': {
                'aa': [2, 5, 8, 14],
                'ua': [1, 2, 3, 5],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'G011',
        },
        'METH1': {
            'rigid': {
                'aa': [2, 5, 8, 10],
                'ua': [1, 2, 3, 4],
                'gamess': [2, 1, 8, 9],
            },
            'name': '4MUW',
        },
        'METH2': {
            'rigid': {
                'aa': [2, 5, 8, 10],
                'ua': [1, 2, 3, 4],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'YE4E',
        },
        'THIO-1': {
            'rigid': {
                'aa': [2, 5, 8, 15],
                'ua': [1, 2, 3, 7],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'ZK6W',
        },
        'THIO0': {
            'rigid': {
                'aa': [2, 5, 8, 12],
                'ua': [1, 2, 3, 7],
                'gamess': [2, 1, 8, 9],
            },
            'name': '1QIU',
        },
        'THIO1': {
            'rigid': {
                'aa': [2, 5, 8, 15],
                'ua': [1, 2, 3, 7],
                'gamess': [2, 1, 8, 9],
            },
            'name': '5G2Q',
        },
        'THIO2': {
            'rigid': {
                'aa': [6, 9, 18, 21],
                'ua': [4, 5, 8, 9],
                'gamess': [2, 1, 8, 9],
            },
            'name': 'PJLY',
        },
    }
    descriptors = {'Original': ['rigid']}
    #'AMINO-1'  : {'gamess':[2,1,8,9], 'aa' : [16,13,7,9], 'ua' : [8,7,5,6], }
    #for m in sorted(molecules):
    #    print("'{}' : {},".format(m, molecules[m]['rigid']))
    #return
    with open(root + '/Parameters/Templates/dihedral.template', 'r') as fh:
        imd_temp_1 = fh.read()
    with open(root + '/Parameters/Templates/dihedral2.template', 'r') as fh:
        imd_temp_2 = fh.read()
    with open(root + '/Parameters/Templates/dihedral3.template', 'r') as fh:
        imd_temp_3 = fh.read()
    with open(root + '/Parameters/Templates/dihedral_constraint.template',
              'r') as fh:
        constraint_temp = fh.read()

    for m in mols:

        forms = dict(mol=m, root=root)
        aa_mtb = inlib.gromos_mtb_parse(
            genlib.load_file(
                '{root}/Parameters/{mol}/{mol}.aa.mtb'.format(**forms)))
        ua_mtb = inlib.gromos_mtb_parse(
            genlib.load_file(
                '{root}/Parameters/{mol}/{mol}.ua.mtb'.format(**forms)))

        aa_work_mol = storage.Molecule(molecules[m]['name'], mtb=aa_mtb)
        ua_work_mol = storage.Molecule(molecules[m]['name'], mtb=ua_mtb)

        for d in descrips:
            forms['des'] = d
            forms['outdir'] = '{root}/{des}/{mol}/MD_data'.format(**forms)
            forms['name'] = molecules[m]['name']
            if not os.path.exists('{outdir}'.format(**forms)):
                os.makedirs('{outdir}'.format(**forms))
            with open('{outdir}/{mol}.aa.1.imd'.format(**forms), 'w') as fh:
                fh.write(
                    imd_temp_1.format(
                        **{'numberOfAtoms': aa_work_mol.atom_count}))
            with open('{outdir}/{mol}.ua.1.imd'.format(**forms), 'w') as fh:
                fh.write(
                    imd_temp_1.format(
                        **{'numberOfAtoms': ua_work_mol.atom_count}))
            with open('{outdir}/{mol}.aa.2.imd'.format(**forms), 'w') as fh:
                fh.write(
                    imd_temp_2.format(
                        **{'numberOfAtoms': aa_work_mol.atom_count}))
            with open('{outdir}/{mol}.ua.2.imd'.format(**forms), 'w') as fh:
                fh.write(
                    imd_temp_2.format(
                        **{'numberOfAtoms': ua_work_mol.atom_count}))
            with open('{outdir}/{mol}.aa.3.imd'.format(**forms), 'w') as fh:
                fh.write(
                    imd_temp_3.format(
                        **{'numberOfAtoms': aa_work_mol.atom_count}))
            with open('{outdir}/{mol}.ua.3.imd'.format(**forms), 'w') as fh:
                fh.write(
                    imd_temp_3.format(
                        **{'numberOfAtoms': ua_work_mol.atom_count}))

            os.chdir('{root}'.format(**forms))

            os.system((
                '/usr/local/gromos++/bin/make_top @build Parameters/{mol}/{mol}.aa.mtb Parameters/54A7.mtb '
                '@param Parameters/54A7.ifp @seq {name} @solv H2O > {outdir}/{mol}.aa.top'
                .format(**forms)))
            os.system((
                '/usr/local/gromos++/bin/make_top @build Parameters/{mol}/{mol}.ua.mtb Parameters/54A7.mtb '
                '@param Parameters/54A7.ifp @seq {name} @solv H2O > {outdir}/{mol}.ua.top'
                .format(**forms)))

            for a in range(0, 360, 5):
                skip_angle = False
                forms['ang2'] = a
                if a == 180:
                    a = 179
                forms['ang'] = a
                try:
                    with open(
                            '{root}/{des}/{mol}/{mol}.{ang:03}.log'.format(
                                **forms), 'r') as fh:
                        gamess = extract_conformation(fh.readlines(),
                                                      scale=1,
                                                      key='name',
                                                      optimised=False)
                except FileNotFoundError:
                    with open(
                            '{root}/{des}/{mol}/{mol}.{ang2:03}.log'.format(
                                **forms), 'r') as fh:
                        gamess = extract_conformation(fh.readlines(),
                                                      scale=1,
                                                      key='name',
                                                      optimised=False)
                for atm in aa_work_mol.atoms:
                    try:
                        atm.xyz = gamess[atm.atm_name.upper()]['vec']
                    except TypeError:
                        print('TypeError', atm.atm_name, d, m, a)
                        skip_angle = True
                        break
                    except KeyError:
                        print('KeyError', atm.atm_name, d, m, a)
                        raise
                if skip_angle:
                    continue
                for atm in ua_work_mol.atoms:
                    atm.xyz = gamess[atm.atm_name.upper()]['vec']
                with open('{outdir}/{mol}.{ang:03}.aa.cnf'.format(**forms),
                          'w') as fh:
                    fh.write(outlib.print_gromos_cnf(aa_work_mol))
                with open('{outdir}/{mol}.{ang:03}.ua.cnf'.format(**forms),
                          'w') as fh:
                    fh.write(outlib.print_gromos_cnf(ua_work_mol))
                #with open('{outdir}/{mol}.{ang:03}.aa.pdb'.format(**forms), 'w') as fh:
                #    fh.write(outlib.print_pdb(aa_work_mol))
                #with open('{outdir}/{mol}.{ang:03}.ua.pdb'.format(**forms), 'w') as fh:
                #    fh.write(outlib.print_pdb(ua_work_mol))
                angs_aa, angs_ua = [], []
                for des in descriptors[d]:
                    atm_a = aa_work_mol.atom(molecules[m][des]['aa'][0]).xyz
                    atm_b = aa_work_mol.atom(molecules[m][des]['aa'][1]).xyz
                    atm_c = aa_work_mol.atom(molecules[m][des]['aa'][2]).xyz
                    atm_d = aa_work_mol.atom(molecules[m][des]['aa'][3]).xyz
                    ang = dihedral_angle(atm_a,
                                         atm_b,
                                         atm_c,
                                         atm_d,
                                         scale='deg')
                    angs_aa.append(
                        '   {1}  {2}  {3}  {4}  1.0  {0:.3f}  0.0   0.0001'.
                        format(ang, *molecules[m][des]['aa']))
                    angs_ua.append(
                        '   {1}  {2}  {3}  {4}  1.0  {0:.3f}  0.0   0.0001'.
                        format(ang, *molecules[m][des]['ua']))
                with open(
                        '{outdir}/{mol}.{ang:03}.aa.constraints.dat'.format(
                            **forms), 'w') as fh:
                    fh.write(
                        constraint_temp.format(
                            **{'constraints': '\n'.join(angs_aa)}))
                with open(
                        '{outdir}/{mol}.{ang:03}.ua.constraints.dat'.format(
                            **forms), 'w') as fh:
                    fh.write(
                        constraint_temp.format(
                            **{'constraints': '\n'.join(angs_ua)}))
                # first pass
                os.system((
                    '/opt/local/gromosXX-1773/bin/md @topo {outdir}/{mol}.aa.top @conf {outdir}/{mol}.{ang:03}.aa.cnf '
                    '@input {outdir}/{mol}.aa.1.imd @fin {outdir}/{mol}.{ang:03}.aa.min.1.cnf @develop '
                    '@dihrest {outdir}/{mol}.{ang:03}.aa.constraints.dat > {outdir}/{mol}.{ang:03}.aa.1.log'
                    .format(**forms)))

                os.system((
                    '/opt/local/gromosXX-1773/bin/md @topo {outdir}/{mol}.ua.top @conf {outdir}/{mol}.{ang:03}.ua.cnf '
                    '@input {outdir}/{mol}.ua.1.imd @fin {outdir}/{mol}.{ang:03}.ua.min.1.cnf @develop '
                    '@dihrest {outdir}/{mol}.{ang:03}.ua.constraints.dat > {outdir}/{mol}.{ang:03}.ua.1.log'
                    .format(**forms)))