def run(pluginManager):
    """
    This is the entry point for the plugin manager.
    The plugin manager will pass a reference to itself
    to the function.
    Use the APD_Printer instance returned by
    pluginManager.setup() instead of the 'print'
    statement to generate autoformated cmd line output.
    :param pluginManager: Reference to the plugin manager
    instance.
    """
    printer = pluginManager.setup()
    printer('Reading database file...')
    for molecule in database(pluginManager):
        h_atoms = atoms_of_element(molecule, 'H')
        if not len(h_atoms) == 0:
            average_bond_length = mean([atom - atom.partner[0] for atom in h_atoms])
        else:
            average_bond_length = 0

        printer('\nName: {}\nInvariom Priority: {}'
                '\nNumber of H atoms: {}'
                '\nAverage H-bond length: {:5.3f}'.format(molecule, molecule.criterion.replace('  ', ''),
                                                          len(h_atoms), average_bond_length))
Exemple #2
0
def run(pluginManager):
    """
    This is the entry point for the plugin manag
    The plugin manager will pass a reference to itself
    to the function.
    Use the APD_Printer instance returned by
    pluginManager.setup() instead of the 'print'
    statement to generate autoformated cmd line output.
    :param pluginManager: Reference to the plugin manager
    instance.
    """
    printer = pluginManager.setup()
    ###--------reading chargeDABA.txt into dictionary chargedict ---------------#
    printer('Reading list of molecules which are model compounds for hydrogen invarioms')
    global hmodelsdict
    global hdistdict
    hmodelsdict = {}
    hdistdict = {}
    path_string = pluginManager.get_databasepath()
    f = open(path_string + '/H_MAP.txt', 'r')
    for line in f.readlines():
        line = line[:-1].split(":")
        hmodelsdict[line[0]] = line[1]
    f.close()
    ###----------------------
    #printer('\nmodelcompound of H@6c:',hmodelsdict["H@6c"])
    #print 'h invariom model compounds in dict as list'
    #print hmodelsdict.values()

    ###----------------------
    printer('Reading database file...')
    count = 0
    altcount = 0
    dist = 0.0
    #print "\nhydrogen.invarioms.keys()[0] bond hydrogen.name name2 name3 \n"
    for molecule in database(pluginManager):
        if molecule.name in list(hmodelsdict.values()):
            #printer(molecule)
            count=count+1
            h_atoms = atoms_of_element(molecule, 'H')
            for hydrogen in h_atoms:
                if molecule.name== hmodelsdict[hydrogen.invarioms.keys()[0]]:
                    bond = hydrogen - hydrogen.partner[0]
                    name2=' '
                    name3=' '
                    if 1 < len(hydrogen.invarioms.keys()):
                        if hydrogen.invarioms.keys()[1] not in hdistdict and molecule.name== hmodelsdict[hydrogen.invarioms.keys()[1]]:
                            altcount= altcount+1
                            name2= hydrogen.invarioms.keys()[1]
                            print("alternative invariom name NOT covered jet!!!", hydrogen.invarioms.keys()[1])
                            hdistdict[hydrogen.invarioms.keys()[1]]   = bond
                        elif molecule.name== hmodelsdict[hydrogen.invarioms.keys()[1]]:
                            print("invariom already present, need to average")
                            print(bond, hdistdict[hydrogen.invarioms.keys()[1]], hydrogen.invarioms.keys()[1])
                            average_bond = mean([bond, hdistdict[hydrogen.invarioms.keys()[1]]])
                            hdistdict[hydrogen.invarioms.keys()[1]] = average_bond
                        #else:
                            #print "alternative name already covered", hydrogen.invarioms.keys()[1]
                    if 2 < len(hydrogen.invarioms.keys()):
                        if hydrogen.invarioms.keys()[2] not in hdistdict and molecule.name== hmodelsdict[hydrogen.invarioms.keys()[2]]:
                            altcount= altcount+1
                            name3= hydrogen.invarioms.keys()[2]
                            print("alternative invariom name NOT covered jet!!!", hydrogen.invarioms.keys()[2])
                            hdistdict[hydrogen.invarioms.keys()[2]]   = bond
                        elif molecule.name== hmodelsdict[hydrogen.invarioms.keys()[2]]:
                            print("invariom already present, need to average")
                            print(bond, hdistdict[hydrogen.invarioms.keys()[2]], hydrogen.invarioms.keys()[2])
                            average_bond = mean([bond, hdistdict[hydrogen.invarioms.keys()[2]]])
                            hdistdict[hydrogen.invarioms.keys()[2]] = average_bond
                        #else:
                           # print "2nd alternative name already covered", hydrogen.invarioms.keys()[2]
                    #print hydrogen.invarioms.keys()[0], bond, hydrogen.name, name2, name3

                    if hydrogen.invarioms.keys()[0] not in hdistdict:
                        hdistdict[hydrogen.invarioms.keys()[0]]   = bond
                        #print "not jet present, but just added:", hydrogen.invarioms.keys()[0], hdistdict[hydrogen.invarioms.keys()[0]]
                    else:
                        #print "invariom already present, need to average"
                        #print bond, hdistdict[hydrogen.invarioms.keys()[0]], hydrogen.invarioms.keys()[0]
                        average_bond = mean([bond, hdistdict[hydrogen.invarioms.keys()[0]]])
                        hdistdict[hydrogen.invarioms.keys()[0]] = average_bond

                #### For those cases in which invariom comes from an atom whose 1st alternative invariom name it is (and the first invariom name is not an invariom supplier)

                elif 1 < len(hydrogen.invarioms.keys()):
                    if molecule.name== hmodelsdict[hydrogen.invarioms.keys()[1]]:
                        print("the alternative invariom name appears in the hmodelsdict thereby in H_MAP.txt", hydrogen.invarioms.keys()[1])
                        bond = hydrogen - hydrogen.partner[0]
                        name2=' '
                        name3=' '
                        if hydrogen.invarioms.keys()[1] not in hdistdict:
                            altcount= altcount+1
                            name2= hydrogen.invarioms.keys()[1]
                            print("alternative invariom name NOT covered jet!!!", hydrogen.invarioms.keys()[1])
                            #else:
                                #print "alternative name already covered", hydrogen.invarioms.keys()[1]
                        if 2 < len(hydrogen.invarioms.keys()):
                            if hydrogen.invarioms.keys()[2] not in hdistdict and molecule.name== hmodelsdict[hydrogen.invarioms.keys()[2]]:
                                altcount= altcount+1
                                name3= hydrogen.invarioms.keys()[2]
                                print("alternative invariom name NOT covered jet!!!", hydrogen.invarioms.keys()[2])
                                hdistdict[hydrogen.invarioms.keys()[2]]   = bond
                            elif molecule.name== hmodelsdict[hydrogen.invarioms.keys()[2]]:
                                print("invariom already present, need to average")
                                print(bond, hdistdict[hydrogen.invarioms.keys()[2]], hydrogen.invarioms.keys()[2])
                                average_bond = mean([bond, hdistdict[hydrogen.invarioms.keys()[2]]])
                                hdistdict[hydrogen.invarioms.keys()[2]] = average_bond

                            #else:
                               # print "2nd alternative name already covered", hydrogen.invarioms.keys()[2]
                        #print hydrogen.invarioms.keys()[0], bond, hydrogen.name, name2, name3

                        if hydrogen.invarioms.keys()[1] not in hdistdict:
                            hdistdict[hydrogen.invarioms.keys()[1]]   = bond
                            #print "not jet present, but just added:", hydrogen.invarioms.keys()[0], hdistdict[hydrogen.invarioms.keys()[0]]
                        else:
                            print("invariom already present, need to average")
                            print(bond, hdistdict[hydrogen.invarioms.keys()[1]], hydrogen.invarioms.keys()[1])
                            average_bond = mean([bond, hdistdict[hydrogen.invarioms.keys()[1]]])
                            hdistdict[hydrogen.invarioms.keys()[1]] = average_bond



                elif 2 < len(hydrogen.invarioms.keys()):
                    if molecule.name== hmodelsdict[hydrogen.invarioms.keys()[2]]:
                        print("the 2nd alternative invariom name appears in the hmodelsdict thereby in H_MAP.txt", hydrogen.invarioms.keys()[2])
                        bond = hydrogen - hydrogen.partner[0]
                        if hydrogen.invarioms.keys()[2] not in hdistdict:
                                altcount= altcount+1
                                print("alternative invariom name NOT covered jet!!!", hydrogen.invarioms.keys()[2])
                                hdistdict[hydrogen.invarioms.keys()[2]]   = bond
                        elif molecule.name== hmodelsdict[hydrogen.invarioms.keys()[2]]:
                                print("invariom already present, need to average")
                                print(bond, hdistdict[hydrogen.invarioms.keys()[2]], hydrogen.invarioms.keys()[2])
                                average_bond = mean([bond, hdistdict[hydrogen.invarioms.keys()[2]]])
                                hdistdict[hydrogen.invarioms.keys()[2]] = average_bond


                #else:
                    #print 'other reason to kick oth this hydrogen atom with invariom:', hydrogen.invarioms.keys()[0]




        #else:
        #    printer ('Entry in H_MAP.txt not looked at', molecule.name  )

    length = 0
    length = len (list( hmodelsdict.values() ))
    printer('The length of the hmodelsdict', length)

    printer('Number of molecules supplying hydrogen invarioms', count)
    printer('Number of alternative H invarioms to be considered (should be zero)', altcount)

    h_invariom_count = 0
    dabafile = open(path_string + '/hdistDABA.txt', 'w')
    for i in range(len(hdistdict)):
        h_invariom_count = h_invariom_count +1
        temp=list(hdistdict.popitem())
        dabafile.writelines(temp[0] + '  ' + str(temp[1]) +'\n')
    printer('Number of hydrogen invarioms written to hdistDABA.txt', h_invariom_count)