Skip to content

Instantly share code, notes, and snippets.

@ajasja
Last active August 2, 2020 06:59
Show Gist options
  • Save ajasja/e5fb13db98835d1d07a31fd6f0017ec4 to your computer and use it in GitHub Desktop.
Save ajasja/e5fb13db98835d1d07a31fd6f0017ec4 to your computer and use it in GitHub Desktop.
def run_command(cmd):
"""Runs command, writes to stdout, raises exception on error"""
print(cmd)
#!{cmd}
exit_code = os.system(cmd)
assert exit_code == 0, 'Error running command'
def prepare_system(input_pdb, out_base, suffix='00_raw', skip_existing=True):
assert os.path.exists(input_pdb), f'{input_pdb} does not exists!'
final_name = f'{out_base}__{suffix}.top'
if skip_existing and os.path.exists(final_name):
print(f'File {final_name} exists. Skipping preparation.')
return final_name
#with Timer(f'Preparing system {input_pdb}...') as t:
pdb4amber_cmd = f'pdb4amber -i {input_pdb} -o {out_base}__{suffix}_00_clean.pdb --nohyd --reduce --dry '+\
'--strip @/H --add-missing-atoms --logfile stdout'
run_command(pdb4amber_cmd)
leap_in = f"""
source leaprc.protein.ff14SBonlysc
set default PBRadii mbondi3
x = loadPDB {out_base}__{suffix}_00_clean.pdb
saveAmberParm x {out_base}__{suffix}.top {out_base}__{suffix}.rst
quit
"""
with open(f'{out_base}__{suffix}_00_leap.in', 'wt') as fin:
print(leap_in, file=fin)
run_command(f'tleap -f {out_base}__{suffix}_00_leap.in')
#TODO clean up all the temp files
return final_name
os.makedirs('out', exist_ok=True)
prepare_system('../../models/1wa3_BA-05_modl.pdb', 'out/1BH_69_modl', suffix='00_raw', skip_existing=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment