示例#1
0
def titrate_one_group(name,intpkas,is_charged,acidbase):
    """Titrate a single group and return the pKa value for it"""
    names=[name]
    num_states=len(intpkas)
    state_counter=[num_states]
    linear=[] # The linear matrix
    for group2 in range(1):
        for state1 in range(num_states):
            for state2 in range(num_states):
                linear.append(0.0)
    #
    # Set the MC parameters
    #
    mcsteps=5000
    phstart=0.1
    phend=20.0
    phstep=0.1
    #
    # Call our little C++ module
    #
    import pMC_mult
    FAST=pMC_mult.MC(intpkas,linear,acidbase,state_counter,is_charged)
    FAST.set_MCsteps(int(mcsteps))
    print 'Calculating intrinsic pKa value'
    pKavals=FAST.calc_pKas(phstart,phend,phstep)
    count=0
    intpka=pKavals[0]
    print 'Simulated intrinsic pKa value: %5.2f' %intpka
    count=1
    #
    # Get the charges
    #
    charges={}
    pH_start=pKavals[count]
    pH_step=pKavals[count+1]
    num_pHs=pKavals[count+2]
    count=count+2
    pHs=[]
    charges=[]
    pH=pH_start
    for x in range(int(num_pHs)):
        count=count+1
        pHs.append(pKavals[count])
        count=count+1
        charges.append(pKavals[count])
        pH=pH+pH_step
    if pKavals[count+1]==999.0 and pKavals[count+2]==-999.0:
        count=count+2
    else:
        print 'Something is wrong'
        print pKavals[count:count+30]
        raise Exception('Incorrect data format from pMC_mult')
    return intpka
示例#2
0
     #
     for group2 in range(groups):
         for state1 in range(states):
             for state2 in range(states):
                 if state1 == 0 and state2 == 0 and group != group2:
                     linear.append(-2.3)
                 else:
                     linear.append(0.0)
 mcsteps = 50000
 phstart = 2.0
 phend = 14.0
 phstep = 0.1
 #
 # Call our little C++ module
 #
 FAST = pMC_mult.MC(intpkas, linear, acidbase, state_counter,
                    is_charged_state)
 FAST.set_MCsteps(int(mcsteps))
 print 'Starting to calculate pKa values'
 pKavals = FAST.calc_pKas(phstart, phend, phstep)
 count = 0
 print '\n****************************'
 print 'Final pKa values'
 pkas = {}
 for name in names:
     pkas[name] = {'pKa': pKavals[count]}
     print '%s pKa: %5.2f ' % (name, pKavals[count])
     count = count + 1
 #
 # Write the WHAT IF pKa file
 #
 for name in names:
示例#3
0
    def _calc_pKas(self,
                   mcsteps=200000,
                   phstep=0.1,
                   phstart=1.0,
                   phend=20.0,
                   verbose=1,
                   complete_pka=None,
                   exp_pHs=[]):
        """Do the pKa calculation with the CPP module"""
        #
        # Do specific CPP_Mult setup
        #
        import time
        starttime = time.time()
        #
        # Get the number of groups
        #
        residues = self.intrinsic_pKa.keys()
        residues.sort()
        #
        # num_states holds the number of states for each group
        # charged_state identified whether a state is charged or neutral
        #
        intpkas = []
        acidbase = []
        num_states = []
        linear_charged_state = []
        for residue in residues:
            num_states.append(len(self.intrinsic_pKa[residue]))
            #this_state=[]
            state_count = 0
            for state in self.intrinsic_pKa[residue]:
                intpkas.append(float(state))
                acidbase.append(int(self.acid_base[residue]))
                linear_charged_state.append(
                    self.charged_state[residue][state_count])
                state_count = state_count + 1
        #
        # Linearise the matrix
        #
        linear_matrix = self.make_matrix_linear()
        #
        # Import the C++ module and run pKa calc from there
        #
        import time, math
        import pMC_mult
        FAST = pMC_mult.MC(intpkas, linear_matrix, acidbase, num_states,
                           linear_charged_state)
        loadtime = time.time()
        #print 'CPP calculations starting at',time.strftime('%d/%m-%Y %H:%M',time.localtime(loadtime))
        FAST.set_MCsteps(int(mcsteps))
        #print 'phstart: %f, phend: %f, phstep: %f' %(phstart,phend,phstep)
        pKa_values = FAST.calc_pKas(phstart, phend, phstep)
        #
        # Put the pKa values back in a dictionary
        #
        pkavalues = {}
        count = 0
        for residue in residues:
            pkavalues[residue] = pKa_values[count]
            if pKa_values[count] < -100.0:
                pkavalues[residue] = -9999.9
            count = count + 1
        #
        # Now get the titration curves
        #
        # pMC returns a specification of how many values it returns
        #
        pH_start = pKa_values[count]
        pH_step = pKa_values[count + 1]
        pH_num = pKa_values[count + 2]
        count = count + 3
        #
        #
        #
        self.pHvalues = []
        self.prot_states = {}
        for residue in residues:
            self.prot_states[residue] = {}
            while 1:
                pH = float(pKa_values[count])
                count = count + 1
                charge = float(pKa_values[count])
                count = count + 1
                #
                # If we find the terminator value
                #
                if pKa_values[count] == 999.0:
                    if pKa_values[count + 1] == -999.0:
                        count = count + 2
                        break
                self.prot_states[residue][pH] = charge
            #
            #
            if self.pHvalues == []:
                self.pHvalues = self.prot_states[residue].keys()
                self.pHvalues.sort()
            #
            # prot_states also contain the pKa value
            #
            self.prot_states[residue]['pKa'] = pkavalues[residue]

        #
        # Construct the proper pKa array
        #
        self.pka = {}
        for group in pkavalues.keys():
            self.pka[group] = {'pKa': pkavalues[group]}
        if complete_pka:
            self.complete_pka()
        #
        # Construct the pHvalues array
        #

        #
        # All done
        #
        loadtid = (loadtime - starttime) / 60.0
        tid = time.time() - starttime
        tid = tid / 60.0
        #print 'CPP calculations took %.4f minutes' %tid
        #print 'setup time %.4f minutes' %loadtid
        #import sys
        #sys.stdout.flush()
        return pkavalues