Esempio n. 1
0
def cartoonize(color, rep):
    """draw a cartoon representation of glycans"""
    stored.ResiduesNumber = []
    cmd.iterate('name c1', 'stored.ResiduesNumber.append((resi))')
    resn_list = [int(i) for i in stored.ResiduesNumber]
    bonds = get_glyco_bonds(resn_list[0], resn_list[-1]+1)
    con_matrix = writer(bonds)
    #con_matrix = writer2(bonds)
    rings = find_rings(resn_list)
    rings_coords = get_ring_coords(resn_list, rings)
    bonds_coords = get_bonds_coords(resn_list, con_matrix)
    colors = get_colors_c1(resn_list, color)
    bonds_colors = get_bonds_colors(resn_list, con_matrix, color)
    cmd.set('suspend_updates', 'on')
    for state, coords in enumerate(rings_coords):
        obj = []
        if rep == 'beads':
            radius_s = 1.8
            radius_b = 0.18
            obj = beads(obj, coords, colors[state], radius_s)
            obj = cylinder(obj, bonds_coords[state], bonds_colors[state], radius_b)
        else:
            if rep == 'cartoon':
                radius = 0.075
            else: 
                radius = 0.035
            obj = hexagon(obj, coords, colors[state], rep, radius)
            obj = cylinder(obj, bonds_coords[state], bonds_colors[state], radius)
        cmd.load_cgo(obj,'cgo01', state+1)

    cmd.select('glycan', 'byres name C1')
    cmd.delete('glycan')
    cmd.delete('tmp')
    cmd.set('two_sided_lighting', 1)
    cmd.set('suspend_updates', 'off')
Esempio n. 2
0
def mcm(pose, mc_steps, SASA, randomize):
    ################################# MCM Parameters ##########################
    T = 300. # Temperature 
    k = 0.0019872041 # Boltzmann constant
    angles_prob = [1/3, 1/3, 1/3] # probability to sample phi, psi or chi
    accepted = 0
    ############################################################################
    # 
    first, last = pose_from_pdb(pose)
    if first or last:
        print('Starting MCM')
        from energy import minimize, set_sasa, get_sasa
        cmd.set('suspend_updates', 'on')
        cmd.feedback('disable', 'executive', 'everything')   ##uncomment for debugging
        cmd.set('pdb_conect_all', 1)
        
        glyco_bonds = get_glyco_bonds(first, last)
        con_matrix = writer(glyco_bonds)
    
        # Remove previous pdb files
        prev_files = glob.glob('mcm_*.pdb')
        for prev_file in prev_files:
            os.remove(prev_file)
    
        # set all paramenters for sasa-energy computation
        if SASA:
            params, points, const = set_sasa(n=1000)
            ## randomize initial conformation
        if randomize:
            for i in range(len(con_matrix)-1):
                bond = con_matrix[i]
                angle_values = np.random.uniform(-180, 180, size=2)
                set_psi(pose, bond, angle_values[0])
                set_phi(pose, bond, angle_values[1])
                for i in range(6):
                    set_chi(pose, bond)
    
        # minimize energy of starting conformation and save it
        NRG_old = minimize(pose, nsteps=5000, rigid_geometry=False)
        NRG_min = NRG_old
        cmd.save('mcm_%08d.pdb' % accepted)
    
        ## start MCM routine
        fd = open("mcm_log.txt", "w")
        print('# iterations remaining = %s' % (mc_steps))
        for i in range(1, mc_steps+1):
            if i % (mc_steps//10) == 0:
                print('#remaining iterations = %s' % (mc_steps-i))
            if True:
                sample_uniform(pose, con_matrix, angles_prob)
            NRG_new = minimize('tmp', nsteps=100, rigid_geometry=False)
            if SASA:
                solvatation_nrg = get_sasa(params, points, const, selection='all',
                 probe=0)[0]
                NRG_new = NRG_new + solvatation_nrg
            if NRG_new < NRG_old:
                NRG_old = NRG_new 
                fd.write('%8d%10.2f\n' % (accepted, NRG_new))
                cmd.copy(pose, 'tmp')
                cmd.delete('tmp')
                cmd.save('mcm_%08d.pdb' % accepted)
                accepted += 1
            else:
                delta = np.exp(-(NRG_new-NRG_old)/(T*k))
                if delta > np.random.uniform(0, 1):
                    NRG_old = NRG_new
                    fd.write('%8d%10.2f\n' % (accepted, NRG_new))
    
                    cmd.copy(pose, 'tmp')
                    cmd.delete('tmp')
                    cmd.save('mcm_%08d.pdb' % accepted)
                    accepted += 1 
            cmd.delete('tmp')
            if NRG_new < NRG_min:
                NRG_min = NRG_new
                cmd.save('mcm_min.pdb')
        fd.close()
    
        cmd.delete('all')
        print('Savings all accepted conformations on a single file')
        cmd.set('defer_builds_mode', 5)
        for i in range(0, accepted):
            cmd.load('mcm_%08d.pdb' % i, 'mcm_trace')
        cmd.save('mcm_trace.pdb', 'all', state=0)
        cmd.delete('all')
        cmd.load('mcm_trace.pdb')
        cmd.intra_fit('mcm_trace')
        print(' MCM completed')
        cmd.set('suspend_updates', 'off')
Esempio n. 3
0
def mcm(pose, mc_steps, SASA, randomize):
    ################################# MCM Parameters ##########################
    T = 300.  # Temperature
    k = 0.0019872041  # Boltzmann constant
    kT = k * T
    # probability to sample phi, psi or chi
    angles_prob = [1 / 3, 1 / 3, 1 / 3]
    accepted = 0
    ##########################################################################
    #
    first, last = pose_from_pdb(pose)
    if first or last:
        print('Starting MCM')
        from energy import minimize, set_sasa, get_sasa
        sus_updates = cmd.get('suspend_updates')
        cmd.set('suspend_updates', 'on')
        # uncomment for debugging
        cmd.feedback('disable', 'executive', 'everything')
        pdb_conect = cmd.get('pdb_conect_all')
        cmd.set('pdb_conect_all', 1)

        glyco_bonds = get_glyco_bonds(first, last)
        con_matrix = writer(glyco_bonds)

        # Remove previous pdb files
        prev_files = glob.glob('mcm_*.pdb')
        for prev_file in prev_files:
            os.remove(prev_file)

        # set all paramenters for sasa-energy computation
        if SASA:
            params, points, const = set_sasa(n=1000)
            # randomize initial conformation
        if randomize:
            for i in range(len(con_matrix) - 1):
                bond = con_matrix[i]
                angle_values = np.random.uniform(-180, 180, size=2)
                set_psi(pose, bond, angle_values[0])
                set_phi(pose, bond, angle_values[1])
                for i in range(6):
                    set_chi(pose, bond)

        # minimize energy of starting conformation and save it
        NRG_old = minimize(pose, nsteps=5000, rigid_geometry=False)
        NRG_min = NRG_old
        cmd.save('mcm_%08d.pdb' % accepted)

        # start MCM routine
        fd = open("mcm_log.txt", "w")
        print('# iterations remaining = %s' % (mc_steps))
        for i in range(1, mc_steps + 1):
            if i % (mc_steps // 10) == 0:
                print('#remaining iterations = %s' % (mc_steps - i))
            if True:
                sample_uniform(pose, con_matrix, angles_prob)
            NRG_new = minimize('tmp', nsteps=100, rigid_geometry=False)
            if SASA:
                solvatation_nrg = get_sasa(params,
                                           points,
                                           const,
                                           selection='all',
                                           probe=0)[0]
                NRG_new = NRG_new + solvatation_nrg
            if NRG_new < NRG_old:
                NRG_old = NRG_new
                fd.write('%8d%10.2f\n' % (accepted, NRG_new))
                cmd.copy(pose, 'tmp')
                cmd.delete('tmp')
                cmd.save('mcm_%08d.pdb' % accepted)
                accepted += 1
            else:
                delta = np.exp(-(NRG_new - NRG_old) / (kT))
                if delta > np.random.uniform(0, 1):
                    NRG_old = NRG_new
                    fd.write('%8d%10.2f\n' % (accepted, NRG_new))

                    cmd.copy(pose, 'tmp')
                    cmd.delete('tmp')
                    cmd.save('mcm_%08d.pdb' % accepted)
                    accepted += 1
            cmd.delete('tmp')
            if NRG_new < NRG_min:
                NRG_min = NRG_new
                cmd.save('mcm_min.pdb')
        fd.close()

        cmd.delete('all')
        print('Savings all accepted conformations on a single file')
        de_builds = cmd.get('defer_builds_mode')
        cmd.set('defer_builds_mode', 5)
        for i in range(0, accepted):
            cmd.load('mcm_%08d.pdb' % i, 'mcm_trace')
        cmd.save('mcm_trace.pdb', 'all', state=0)
        cmd.delete('all')
        cmd.load('mcm_trace.pdb')
        cmd.intra_fit('mcm_trace')
        print('MCM completed')
        # restore settings
        cmd.set('suspend_updates', sus_updates)
        cmd.set('pdb_conect_all', pdb_conect)
        cmd.set('defer_builds_mode', de_builds)