#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys, requests, json # Script POSTs coordinates for NtC assignment to DNATCO web server ################# settings ################# # using the default DNATCO version (v3.2 as of 03 Aug 2021) with NtC alphabet version 3.5 dnatco_cgi = "https://dnatco.datmos.org/cgi-bin/assign_from_coords_35.py" # set user agent for logging purposes headers = {'user-agent': 'POST_json_coords.py/0.0.2'} ############################################ # Step name and coordinates of 20 atoms within a step are needed. # Atom names use "p" instead of "'" (prime) and "a/b" for first/second residue within a step. # Purine/pyrimidine atom names are combined to "N19" and "C24" for simplicity. # Coordinates in Angstroms are expected as strings in x,y,z order for each atom, i.e. ["x.x", "y.y", "z.z"] # use example json query ... #query = '{"step_id":"102d_A_DC_1_DG_2","C5pa":["18.939","34.713","89.428"],"C4pa":["20.086","33.755","89.286"],"O4pa":["19.617","32.539","89.905"],"C3pa":["20.434","33.382","87.819"],"O3pa":["21.831","32.949","87.719"],"C2pa":["19.488","32.196","87.629"],"C1pa":["19.521","31.485","88.974"],"N19a":["18.313","30.732","89.375"],"C24a":["18.488","29.453","89.907"],"Pb":["22.636","32.521","86.331"],"O5pb":["22.776","30.956","86.326"],"C5pb":["23.239","30.276","87.446"],"C4pb":["23.441","28.853","87.109"],"O4pb":["22.221","28.177","87.390"],"C3pb":["23.649","28.619","85.571"],"O3pb":["24.497","27.474","85.326"],"C2pb":["22.244","28.333","85.091"],"C1pb":["21.634","27.584","86.246"],"N19b":["20.190","27.715","86.370"],"C24b":["19.318","26.753","86.864"]}' # ... or read prepared json from cmdline query = sys.argv[1] try: # POST json query to DNATCO r = requests.post(dnatco_cgi, json=json.loads(query), headers=headers) # decode returned json jsonres = r.json() except Exception as e: print(repr(e)) sys.exit() # "error" is empty for successful assignment if (jsonres["error"] == ""): # save json output to file try: out = open(jsonres["result"]["step_id"] + ".json", "w") json.dump(jsonres, out) out.close() except: print("Error writing output json file") pass # process json output # print full output #print(jsonres) # and/or only selected summary print(jsonres["result"]["NtC"], jsonres["result"]["nearest_NtC"], jsonres["result"]["confalH"], jsonres["result"]["rmsd"]) else: print(jsonres["error"])