Skip to content

Commit

Permalink
Version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
souadyoujilabadi committed Sep 13, 2022
1 parent 70516b8 commit 74a860a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
5 changes: 3 additions & 2 deletions bin/SASA.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def SASA(): #The main.

dico[pos] = (name_res, num_res, round(s_exp_abs_res, 2), round(s_exp_rel_res, 2), round(perc_res, 2)) #In homodimers, residue names and numbers are the same in both chains. For this reason, pos (position) is used as key.

print(dico)
headers = ["POS", "RES", "NUM", "S-ABS", "S-REL", "PERC"]
print(tabulate([(k,) + v for k, v in dico.items()], headers=headers))

Expand All @@ -86,8 +87,8 @@ def SASA(): #The main.

print(f"--- {(time.time() - start_time):.2f} seconds ---") #Time taken for the program execution.

#NB: The main has no return
#Example of use : python3 SASA.py -pdb data/pdb/1bzv.pdb -n 92
#NB: The main has no return.
#Example of use : python3 bin/SASA.py -pdb data/pdb/1bzv.pdb -n 92


if __name__ == "__main__": #If the program SASA.py is executed as a script in a shell, the result of the if test will be True and the corresponding instruction block will be executed.
Expand Down
19 changes: 2 additions & 17 deletions bin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ def atomic_coordinates(pdb):
Return:
df: DataFrame containing the atomic coordinates and the other mentioned associated data.
"""

with open(pdb, "r") as pdb_file: #Open the PDB file in read "r" mode.

atom_data = {"res_name" : [], "res_num" : [], "atom_name" : [], "x" : [], "y" : [], "z" : []} #Declare a dictionary, {key : value}, in which values = empty lists.
atoms_names, res_names, res_nums, x, y, z = [], [], [], [], [], [] #Create empty lists.
#count_atoms = 0 #If we want to count the number of atoms.

for line in pdb_file:
if line.startswith("ATOM"): #Take only the lines starting with ATOM. These lines contain the protein atoms. (It is necessary to exclude the other lines, e.g. the lines starting with HETATM (= correspond to atoms that belong to other molecules, e.g. ions and H2O).
atoms_names.append(line[13].strip()) #Take only the first letter of an atom name (e.g. C instead of CA, CB, ...), remove any leading (spaces at the beginning) and trailing (spaces at the end) characters with the method .strip(), and add it to the list atoms_names using the method .append().
Expand All @@ -41,17 +38,13 @@ def atomic_coordinates(pdb):
x.append(float(line[30:38])) #Extracte the x coordinate, and add it to the list called x.
y.append(float(line[38:46]))
z.append(float(line[46:54]))
#count_atoms += 1

#count_atoms += 1
#"This protein contains {} atoms".format(count_atoms)

atom_data["res_name"] = res_names #Assign the list res_names to the key "res_name".
atom_data["res_num"] = res_nums
atom_data["atom_name"] = atoms_names
atom_data["x"], atom_data["y"], atom_data["z"] = x, y, z

df = pd.DataFrame(atom_data) #Create a DataFrame with the atom_data dictionary, (the keys become the column names).

return df


Expand All @@ -66,26 +59,21 @@ def sphere(n, center, r_vdw):
Return:
points_coordinates: Array containing the points coordinates.
"""

ind = np.arange(n) #Create an array (vector) object of n integers.
phi = np.pi * (3 - np.sqrt(5)) #Golden angle (= 2.39996 rad, 137,51 °)
theta = phi * ind #Golden angle increment/Theta angle
z = np.linspace(start=1 , stop=-1, num=n) #Create the variable z with the function linspace() which returns an array of n evenly spaced numbers over the specified interval, [1, -1]. (=Z axis)
r = np.sqrt(1 - z**2) #Circles radius
r_sphere = r_vdw + 1.4 #Sphere defined radius (= sphere size): Van der Waals radius of an atom + Van der Waals radius of Oxygen (= 1.4).

#Points coordinates:
z = np.add(z * r_sphere, center[2])
x = np.add(r * np.cos(theta) * r_sphere, center[0])
y = np.add(r * np.sin(theta) * r_sphere, center[1])

y = np.add(r * np.sin(theta) * r_sphere, center[1])
points_coordinates = np.zeros(shape=(n, 3)) #Create an array of given shape (= n sequences containing 3 zeros each).
points_coordinates[:, 0] = x #Replace the first zero of each sequence by the x coordinates.
points_coordinates[:, 1] = y
points_coordinates[:, 2] = z

#pp.figure().add_subplot(projection="3d").scatter(x, y, z) #If we want to visualize the sphere.

return points_coordinates#, pp.show()


Expand All @@ -98,7 +86,6 @@ def check_distance(r_vdw, distance):
Return:
distance < r_vdw + 1.4: True or False.
"""

return distance < (r_vdw + 1.4) #True (= hidden points) or False (= solvent-exposed points).


Expand All @@ -113,9 +100,7 @@ def surface_exp(r_vdw, points_exp, n):
s_exp: Sphere's exposed surface area.
s_tot: Sphere's total surface area (exposed + hidden).
"""

s_tot = 4 * np.pi * (r_vdw + 1.4)**2 #Surface area of a sphere.
ratio_exp = points_exp / n #Accessibility ratio.
s_exp = s_tot * ratio_exp #Cross-multiplication.

return s_exp, s_tot
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ channels:
- anaconda
dependencies:
- python=3.10
- matplotlib
- numpy
- pandas
- matplotlib
- tqdm
- joblib
- tabulate
- joblib


0 comments on commit 74a860a

Please sign in to comment.