<jupyter_start><jupyter_text>Ramachandran plot and DSSP with MDAnalysis  Ramachandran plot with MDA<jupyter_code>import pytraj as pyt
import numpy as np
data_dir = './dm_sources_1L2Y/'
# Cargamos el archivo de topología y seleccionamos los residuos de la proteína
f_topology = F'{data_dir}/4-run_dm_2/tc5b_wb.psf'
top_psf = pyt.load_topology(f_topology)[':1-20']
top_psf
# Cargamos el archivo con la trayectoria total
f_full_traj = F'{data_dir}/5-traj_analysis/tc5b_PROT_FULL_TRAJ.dcd'
full_traj = pyt.load(filename = f_full_traj, top = top_psf)
full_traj
# Cargamos la estructura NMR
nmr_strc = pyt.load(filename = F'{data_dir}/5-traj_analysis/1l2y_Hs.pdb',
                  top = F'{data_dir}/5-traj_analysis/1l2y_Hs.psf')
# Definimos frames claves para evaluarlos
first_frame = full_traj[0]
last_frame = full_traj[-1]
import matplotlib.pyplot as plt
import seaborn as sns
# Carga de la gráfica de referencia
a = np.loadtxt('https://raw.githubusercontent.com/jRicciL/MD_namd_python/master/dm_sources_1L2Y/0-inputs/ramchandran_references/pref_general.data.txt')

a= a.T
#a = np.compress( a[2] > 0.03, a, axis=1)
#len(a[1])
a[2][a[2]  > 0.001] = 3
a.T
10**(-10)
a = np.loadtxt('https://raw.githubusercontent.com/jRicciL/MD_namd_python/master/dm_sources_1L2Y/0-inputs/ramchandran_references/pref_general.data.txt')

a= a.T
a[2].max()
a = np.loadtxt('https://raw.githubusercontent.com/jRicciL/MD_namd_python/master/dm_sources_1L2Y/0-inputs/ramchandran_references/pref_general.data.txt')

a= a.T

a[2][(a[2]  > 0.1)] = 10
a[2][(a[2]  > 0.01) & (a[2]  < 0.1)] = 1
a[2][(a[2]  > 0.001) & (a[2]  < 0.01)] = 0.1
a[2][(a[2]  > 0.0001) & (a[2]  < 0.001)] = 0.01
a[2][(a[2]  < 0.0001)] = 0.001
a = np.loadtxt('https://raw.githubusercontent.com/jRicciL/MD_namd_python/master/dm_sources_1L2Y/0-inputs/ramchandran_references/pref_general.data.txt')

a= a.T
for i in range(0, 5):
    print(10**(-i))
    a[2][(a[2]  > 10**(-i-1)) & (a[2]  < 10**(-i))] = 10 * (2**(-i+1)) / 2
    print(10 * (2**(-i+1)) / 2)
a[2][(a[2]  < 0.0001)] = 0.0

a[2].max()
fig, ax = plt.subplots()
ax.scatter(a[0], a[1], s=a[2], alpha = 0.3)

plt.show()

path = './dm_sources_1L2Y/0-inputs/ramchandran_references'
files = ['general', 'glycine', 
         'proline', 'preproline']

for file in files:
    a = np.loadtxt(F'{path}/pref_{file}.data.txt')
    a = a.T
    for i in range(0, 6):
        a[2][(a[2]  > 10**(-i-1)) & (a[2]  < 10**(-i))] = 10 * (2**(-i+1)) / 2
    a[2][(a[2]  < 0.001)] = 0
    a = np.compress(a[2] != 0, a, axis=1)
    # Guarda el archivo
    save_path = F'{path}/pref_{file}'
    np.save(save_path, a)
from  matplotlib import pyplot as plt
import seaborn as sns
import pylab
sns.set( context = 'talk', style = 'ticks', palette = "Spectral")
pylab.rcParams['figure.figsize'] = (10, 10)

colors = {'general': "#7ED5F6", 'glycine': "#FADD9A",
        'proline': '#7DDAAD', 'preproline': '#E19AFA'}

path = './dm_sources_1L2Y/0-inputs/ramchandran_references'
data = { i: np.load(F'{path}/pref_{i}.npy') for i in colors.keys()}

fig, axs = plt.subplots(2, 2, figsize = plt.figaspect(1))
for ax, plot in zip(axs.flat, data.keys()):
    x = data[plot]
    my_cmap = sns.blend_palette(['white', colors[plot]], as_cmap=True)
    ax.set_xlim(-180, 180)
    ax.set_ylim(-180, 180)
    ax.axhline(y=.0, linestyle = '--', c = 'black', lw = 1.2)
    ax.axvline(x=.0, linestyle = '--', c = 'black', lw = 1.2)
    ax.tricontourf(x[0], x[1], x[2], cmap = my_cmap)
    ax.set(xlabel=r'$\Phi$', ylabel=r'$\Psi$')
    ax.label_outer()
import matplotlib.tri as tri
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import ListedColormap

a = np.loadtxt('./dm_sources_1L2Y/0-inputs/ramchandran_references/pref_glycine.data.txt')
print(a.shape)
a= a.T
for i in range(0, 5):
    a[2][(a[2]  > 10**(-i-1)) & (a[2]  < 10**(-i))] = 10 * (2**(-i+1)) / 2
a[2][(a[2]  < 0.001)] = 0
a = np.compress(a[2] != 0, a, axis=1)


print(a[2].min())

my_cmap = sns.blend_palette(["#FFFFFF", "#21B4D5"], as_cmap=True)
plt.tricontourf(a[0], a[1], a[2], cmap = my_cmap, alpha = 0.5)
a.shape
# Gráfico de Ramachandran
# Cristal
angles = pyt.multidihedral(nmr_strc, 'phi psi', resrange=range(20))

# take data for 'phi' and flatten to 1D array
phi = np.array([d.values for d in angles if 'phi' in d.key]).flatten()

# take data for 'psi' and flatten to 1D array
psi = np.array([d.values for d in angles if 'psi' in d.key]).flatten()

# setup color
colors = np.random.rand(len(psi))

plt.xlim([-180, 180])
plt.ylim([-180, 180])
plt.xlabel('phi')
plt.ylabel('psi')
plt.grid()
plt.scatter(phi, psi, alpha=0.5, c=colors)
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import  GRO, XTC
u = mda.Universe(GRO, XTC)

# selection of atomgroups
ags = [res.phi_selection() for res in u.residues[4:9]]

from MDAnalysis.analysis.dihedrals import Dihedral
R = Dihedral(ags).run()
import matplotlib.pyplot as plt
from MDAnalysis.analysis.dihedrals import Ramachandran

u = mda.Universe('./dm_sources_1L2Y/5-traj_analysis/1l2y_Hs.psf',
               './dm_sources_1L2Y/5-traj_analysis/1l2y_Hs.pdb')
r = u.select_atoms("resid 2-19")

R = Ramachandran(r).run()
fig, ax = plt.subplots(figsize = plt.figaspect(1))
R.plot(ref = True)
u.trajectory[10]
dir(u)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1902132520944402, 'fraction_numerical': 0.05293221629855293, 'mean_word_length': 4.160117878192534, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '298146', 'license': 'MIT', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2364, 'n_words': 453, 'path': 'Ramachandran_plot_and_DSSP.ipynb', 'repo_name': 'jRicciL/MD_namd_python', 'size': '5252'}