|
| 1 | +""" |
| 2 | +
|
| 3 | +@author: nabin |
| 4 | +
|
| 5 | +This script extracts carbon-alpha only atoms from protein structure (.pdb) and saves it. |
| 6 | +python3 get_ca_labels.py <input protein structure path> <output protein only ca structure path> |
| 7 | +
|
| 8 | +""" |
| 9 | + |
| 10 | +from Bio import PDB |
| 11 | +import os |
| 12 | +import sys |
| 13 | + |
| 14 | +def save(x, y, z, count, amino_name, chain_id, true_ca_path): |
| 15 | + atom = 'CA' |
| 16 | + residue_name = amino_name |
| 17 | + with open(true_ca_path, 'a') as fi: |
| 18 | + fi.write('ATOM') |
| 19 | + fi.write(' ') |
| 20 | + fi.write(str(count).rjust(5)) |
| 21 | + fi.write(' ') |
| 22 | + fi.write(atom.ljust(4)) |
| 23 | + fi.write(residue_name.rjust(3)) |
| 24 | + fi.write(' ') |
| 25 | + fi.write(chain_id) |
| 26 | + fi.write(str(count).rjust(4)) |
| 27 | + fi.write(' ') |
| 28 | + fi.write(str(x).rjust(8)) |
| 29 | + fi.write(str(y).rjust(8)) |
| 30 | + fi.write(str(z).rjust(8)) |
| 31 | + fi.write(str(1.00).rjust(5)) |
| 32 | + fi.write(str(0.00).rjust(5)) |
| 33 | + fi.write(' ') |
| 34 | + fi.write(atom[0:1].rjust(1)) |
| 35 | + fi.write(' ') |
| 36 | + fi.write('\n') |
| 37 | + |
| 38 | + |
| 39 | +def label_mask(pdb_path, true_ca_path): |
| 40 | + count = 0 |
| 41 | + |
| 42 | + parser = PDB.PDBParser(QUIET=True) |
| 43 | + pdb_map = pdb_path |
| 44 | + struct = parser.get_structure("CA", pdb_map) |
| 45 | + for model in struct: |
| 46 | + for chain in model: |
| 47 | + for residue in chain: |
| 48 | + for atom in residue: |
| 49 | + if atom.get_name() == "CA": |
| 50 | + x, y, z = atom.get_coord() |
| 51 | + amino_name = residue.resname |
| 52 | + chain_id = chain.id |
| 53 | + save(x, y, z, count, amino_name, chain_id, true_ca_path) |
| 54 | + count += 1 |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + |
| 59 | + input_pdb = sys.argv[1] |
| 60 | + true_ca_pdb = sys.argv[2] |
| 61 | + if os.path.exists(true_ca_pdb): |
| 62 | + os.remove(true_ca_pdb) |
| 63 | + label_mask(input_pdb, true_ca_pdb) |
| 64 | + print("########## NG: get_ca_labels: DONE ##########") |
| 65 | + |
0 commit comments