-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathget_mol_center.py
executable file
·29 lines (21 loc) · 1.02 KB
/
get_mol_center.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
#!/usr/bin/env python3
__author__ = 'Pavel Polishchuk'
import argparse
import numpy as np
from read_input import read_input
def main():
parser = argparse.ArgumentParser(description='Returns a geometrical center of input 3D molecules. '
'All explicit atoms will be considered.')
parser.add_argument('-i', '--input', metavar='FILENAME', required=True,
help='input SDF file with 3D structures.')
parser.add_argument('-o', '--output', metavar='FILENAME', required=True,
help='text file with molecule name and three columns of x, y and z coordinates. No header.')
args = parser.parse_args()
with open(args.output, 'wt') as fout:
for mol, mol_name in read_input(args.input):
conf = mol.GetConformer()
xyz = conf.GetPositions()
res = np.mean(xyz, axis=0)
fout.write(mol.GetProp('_Name') + '\t' + '\t'.join(map(str, res)) + '\n')
if __name__ == '__main__':
main()