0
|
1 #!/usr/bin/env python
|
|
2 """
|
|
3 Input: molecular input file.
|
|
4 Output: Molecule file with removed ions and fragments.
|
|
5 Copyright 2012, Bjoern Gruening and Xavier Lucas
|
|
6 """
|
|
7 import sys, os
|
|
8 import argparse
|
|
9 import openbabel
|
|
10 openbabel.obErrorLog.StopLogging()
|
|
11 import pybel
|
|
12
|
|
13 def parse_command_line():
|
|
14 parser = argparse.ArgumentParser()
|
|
15 parser.add_argument('-iformat', default='sdf' , help='input file format')
|
|
16 parser.add_argument('-i', '--input', required=True, help='input file name')
|
|
17 parser.add_argument('-o', '--output', required=True, help='output file name')
|
|
18 return parser.parse_args()
|
|
19
|
|
20 def remove_ions(args):
|
|
21 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
|
|
22 for mol in pybel.readfile(args.iformat, args.input):
|
|
23 if mol.OBMol.NumHvyAtoms() > 5:
|
|
24 mol.OBMol.StripSalts(0)
|
|
25 # Check if new small fragments have been created and remove them
|
|
26 if mol.OBMol.NumHvyAtoms() > 5:
|
|
27 outfile.write(mol)
|
|
28 outfile.close()
|
|
29
|
|
30 def __main__():
|
|
31 """
|
|
32 Remove any counterion and delete any fragment but the largest one for each molecule.
|
|
33 """
|
|
34 args = parse_command_line()
|
|
35 remove_ions(args)
|
|
36
|
|
37 if __name__ == "__main__" :
|
|
38 __main__()
|