<jupyter_start><jupyter_text>Homework 3 Submitted by : <NAME>  Task 1: Topologies  Print the coordinates and explain the shape of the returned array<jupyter_code>%matplotlib inline
import numpy as np
import mdtraj as md
coord = md.load('alanine-dipeptide-nowater.pdb')
coord<jupyter_output><empty_output><jupyter_text>The file has 22 atoms in 1 frame.<jupyter_code>coord = md.load('alanine-dipeptide-nowater.pdb')
atoms, bonds = coord.topology.to_dataframe()
atoms
print(coord.xyz[0])
### task: "please discuss the shape of the returned array"
### 0.5/1<jupyter_output><empty_output><jupyter_text>Print a list of all heavy atoms (i.e. everything else than hydrogen) with their indices, names and elements.<jupyter_code>atoms.loc[atoms.element != 'H']
### 1/1<jupyter_output><empty_output><jupyter_text>Function to calculate two angles $\phi$ and $\psi$<jupyter_code>### please write definition in mathematical terms here
def new_dihedral(p):
    p0 = p[0]
    p1 = p[1]
    p2 = p[2]
    p3 = p[3]

    b0 = -1.0*(p1 - p0)
    b1 = p2 - p1
    b2 = p3 - p2

    b1 /= np.linalg.norm(b1) # normalize b1 so that it does not influence magnitude of vector

    v = b0 - np.dot(b0, b1)*b1
    w = b2 - np.dot(b2, b1)*b1

    x = np.dot(v, w)
    y = np.dot(np.cross(b1, v), w)
    return np.degrees(np.arctan2(y, x))
# Defining the coordinates for the calculation of angle phi
p0 = np.array([2.77, 25.8, 1.23]) # C (indices 4)
p1 = np.array([3.27, 24.64, 0.69]) # N (indices 6)
p2 = np.array([2.48, 23.69, -0.19]) # CA (indices 8) 
p3 = np.array([1.73, 22.59, 0.49])  # C (indices 14)
new_dihedral(np.array([p0, p1, p2, p3]))
np.allclose(coord.xyz[0, [4, 6, 8, 14]], np.array([p0, p1, p2, p3])/10)
np.radians(new_dihedral(np.array([p0, p1, p2, p3])))<jupyter_output><empty_output><jupyter_text>Now we can compare this to the output of the MDtraj output :<jupyter_code>md.compute_phi(coord )<jupyter_output><empty_output><jupyter_text>The angle $-89.99^{\circ}$-> $-1.57$ radians. We can see that both methods gives the same result. Now we can check for the angle $\psi$<jupyter_code># Defining the coordinates for the calculation of angle psi
p0 = np.array([3.27, 24.64, 0.69]) # N (indices 6)
p1 = np.array([2.48, 23.69, -0.19]) # CA (indices 8)
p2 = np.array([1.73, 22.59, 0.49]) # C (indices 14)
p3 = np.array([0.4, 22.43, 0.21])  # N (indices 16)
new_dihedral(np.array([p0, p1, p2, p3]))
np.radians(new_dihedral(np.array([p0, p1, p2, p3])))<jupyter_output><empty_output><jupyter_text>Convering $127.80^{\circ} = 2.23 $ radians.<jupyter_code>md.compute_psi(coord )<jupyter_output><empty_output><jupyter_text>We can see that both methods gives exactly the same results.<jupyter_code>### it would be simpler if you could obtain the variables p0, p1, ...
### not by copy-pasting - it will become too complicated for larger systems.
### here: coord.xyz[0, [4, 6, 8, 14]] = np.array([p0, p1, p2, p3])/10

### units: radians and nanometers are preferred units

### 3/3
### mdtraj: 1/1<jupyter_output><empty_output><jupyter_text>Distances between the heavy atoms that forms a bond.<jupyter_code>h1 = np.array([[4.259, 24,471], [0.81, -0.008, 23.118, -0.407]])
#h2 = np.array([-0.008, 23.118, -0.407])
md.compute_distances(coord, h1)
### 0/1<jupyter_output><empty_output><jupyter_text>The harmonic bond potential can be used to to approximate the atom-atom distance. The equation that describes the potential energy of the system is given as$$V_{B} = k(r_{ij} - r_0)$$$r_0$ is the reference bond length and $r_{ij}$ is the distance between atom $i$ and $j$.<jupyter_code>### yes, correct!<jupyter_output><empty_output><jupyter_text>Task 2 : Trajectories<jupyter_code>import mdshare
files = mdshare.fetch('alanine-dipeptide-*-250ns-nowater.xtc', 
                      working_directory='.')
md.load_xtc('alanine-dipeptide-0-250ns-nowater.xtc', coord)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15684754521963823, 'fraction_numerical': 0.06563307493540052, 'mean_word_length': 4.602026049204052, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 47, 'https://': 0, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '180347', 'license': 'MIT', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1512, 'n_words': 401, 'path': 'HW3/HW_3_yadev.ipynb', 'repo_name': 'mahesh27dx/molecular_phys', 'size': '3876'}