Skip to content

Instantly share code, notes, and snippets.

@leelasd
Created April 4, 2017 20:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leelasd/996158d2be9885e3a1caeb25d6f979f9 to your computer and use it in GitHub Desktop.
Save leelasd/996158d2be9885e3a1caeb25d6f979f9 to your computer and use it in GitHub Desktop.
Combine .ITP files from gromacs into 'combo.itp' file
def read_itp(itp_name):
lines = open(itp_name).readlines()
impDat = []
for n in range(len(lines)):
if '[' in lines[n]: impDat.append(n)
atom_def = lines[impDat[0]+1:impDat[1]]
rest_mol = lines[impDat[1]:]
return(atom_def,rest_mol)
a_UNK,r_UNK=read_itp('UNK.itp')
a_OCT,r_OCT=read_itp('OCT.itp')
a_CYH,r_CYH=read_itp('CYH.itp')
atypes = list(set(a_UNK +a_OCT + a_CYH))
moltypes = r_UNK + r_OCT + r_CYH
ofile=open('combo.itp','w')
ofile.write('[ atomtypes ] \n')
for line in atypes: ofile.write('%s'%line)
for line in moltypes: ofile.write('%s'%line)
ofile.close()
print('-maxwarn %d'%(len(a_CYH+a_OCT)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment