forked from devalab/DeepPocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_and_gninatyper.py
44 lines (40 loc) · 1.42 KB
/
types_and_gninatyper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
creates types and gninatypes files of the protein for input to CNN via libmolgrid
first argument is path to protein file
second argument is path to barycenters list file
'''
import molgrid
import struct
import numpy as np
import os
import sys
from model import Model
def gninatype(file):
# creates gninatype file for model input
f=open(file.replace('.pdb','.types'),'w')
f.write(file)
f.close()
atom_map=molgrid.FileMappedGninaTyper('gninamap')
dataloader=molgrid.ExampleProvider(atom_map,shuffle=False,default_batch_size=1)
train_types=file.replace('.pdb','.types')
dataloader.populate(train_types)
example=dataloader.next()
coords=example.coord_sets[0].coords.tonumpy()
types=example.coord_sets[0].type_index.tonumpy()
types=np.int_(types)
fout=open(file.replace('.pdb','.gninatypes'),'wb')
for i in range(coords.shape[0]):
fout.write(struct.pack('fffi',coords[i][0],coords[i][1],coords[i][2],types[i]))
fout.close()
os.remove(train_types)
return file.replace('.pdb','.gninatypes')
def create_types(file,protein):
# create types file for model predictions
fout=open(file.replace('.txt','.types'),'w')
fin =open(file,'r')
for line in fin:
fout.write(' '.join(line.split()) + ' ' + protein +'\n')
return file.replace('.txt','.types')
if __name__ == '__main__':
protein=gninatype(sys.argv[1])
types=create_types(sys.argv[2],protein)