
import chempy

def get_partial_charge(model):
   if chempy.feedback['verbose']:
      print ' '+str(__name__)+': generating partial charge keywords...'
   list = []
   c = -1
   for a in model.atom:
      list.append("CHARGE %d %6.4f\n" %(c,a.partial_charge))
      c = c - 1
   return list


def get_restrain_positions(model,flag,w_width,f_cnst):
   list = []
   n = 0
   c = 1
   mask = 1<<flag
   for a in model.atom:
      if (a.flags&mask):
         list.append("RESTRAIN-POSITION %5d %12.6f %12.6f %12.6f %6.3f %6.1f\n" %
                     (c,a.coord[0],a.coord[1],a.coord[2],w_width,f_cnst))
         n = n + 1
      c = c + 1
   if chempy.feedback['actions']:
      print ' '+str(__name__)+': %d atoms restrained using flag %d ...' % (n,flag)
      
   return list

def get_inactive(model,flag):
   list = []
   n = 0
   c = 1
   mask = 1<<flag
   for a in model.atom:
      if (a.flags&mask):
         list.append("INACTIVE %d\n" % (c))
         n = n + 1
      c = c + 1
   if chempy.feedback['actions']:
      print ' '+str(__name__)+': %d atoms fixed using flag %d ...' % (n,flag)
   return list

