File: assignBondOrders.py

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (73 lines) | stat: -rw-r--r-- 2,497 bytes parent folder | download | duplicates (8)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
# Anna Dehof 2011-10-20
#   Compute and assign bond orders for a given 
#   ligand based on atomic valence penalty rules.
#

import sys
from BALL import *

# for use in BALLView
#system = getSystems()[0]

#### for command line use	
# issue a usage hint if called without parameters
if (len(sys.argv) != 3 ):
  print"Usage: ", sys.argv[0] , " <Ligand infile> <Ligand outfile>" 
  exit()

# open the file
file = MOL2File(sys.argv[1], File.MODE_IN)

if (not file):
  # if file does not exist: complain and abort
  print "error opening ", sys.argv[1], " for input."
  exit ()

# create a system and read the contents of the PDB file
system = System()
file.read(system)
file.close()

# print the number of atoms read from the file
print "Read", system.countAtoms(), "atoms and", system.countBonds(), "bonds from file"
print  "   ", sys.argv[1]

# create an BondOrderAssignmentProcessor
abop = AssignBondOrderProcessor()
abop.options.setBool(AssignBondOrderProcessor.Option.KEKULIZE_RINGS, True) 
abop.options.setBool(AssignBondOrderProcessor.Option.OVERWRITE_SINGLE_BOND_ORDERS, True)
abop.options.setBool(AssignBondOrderProcessor.Option.OVERWRITE_DOUBLE_BOND_ORDERS, True)
abop.options.setBool(AssignBondOrderProcessor.Option.OVERWRITE_TRIPLE_BOND_ORDERS, True)
abop.options.set(AssignBondOrderProcessor.Option.ALGORITHM, AssignBondOrderProcessor.Algorithm.A_STAR)
abop.options.setReal(AssignBondOrderProcessor.Option.BOND_LENGTH_WEIGHTING,0)
abop.options.setInteger(AssignBondOrderProcessor.Option.MAX_NUMBER_OF_SOLUTIONS,10)
abop.options.setBool(AssignBondOrderProcessor.Option.COMPUTE_ALSO_NON_OPTIMAL_SOLUTIONS, True)
abop.options.setBool(AssignBondOrderProcessor.Option.ADD_HYDROGENS, False)

print "Current penalty: " , abop.evaluatePenalty(system)

# apply the processor
system.apply(abop)

print "Computed", abop.getNumberOfComputedSolutions(), "bond order assignments:"

# print all solutions penalty
for i in range(abop.getNumberOfComputedSolutions()):
  print "   solution", str(i) , ": penalty", str(abop.getTotalPenalty(i)) #, " , ", abop.getNumberOfAddedHydrogens(i) , " added hydrogens."	
  # apply the i-th solution
  if (abop.apply(i)):
    # and write the solution into an MOL2file	
    outfile_name = String(sys.argv[2]) + "_" + str(i) + ".mol2";
    print "   Writing solution", i, "as", outfile_name
    outfile = MOL2File(outfile_name, File.MODE_OUT)
    outfile.write(system)
    outfile.close()

# done
print "Done."

# for use in BALLView
#getMainControl().update(system)