python-package-best-practices icon indicating copy to clipboard operation
python-package-best-practices copied to clipboard

symbols typed as Numpy array out of nowhere

Open radifar opened this issue 4 years ago • 0 comments

Now I understand why in Episode 4 section Editing function to our package, the symbols variable output was written as array(['O', 'H', 'H'], dtype='<U1') which then I updated to ['O', 'H', 'H']. When I reached Whitespace subsection, open_pdb becomes:

def open_pdb(file_location):
    
    with open(file_location) as f:
        data = f.readlines()

    coordinates = []
    symbols = []
    for line in data:
        if 'ATOM' in line[0:6] or 'HETATM' in line[0:6]:
            symbols.append(line[76:79].strip())
            atom_coords = [float(x) for x in line[30:55].split()]
            coordinates.append(coords)

    coords = np.array(coordinates)
    symbols = np.array(symbols)

    return symbols, coords

Notice that "suddenly" symbols = np.array(symbols) came out of nowhere. Thus, we need to add some explanation for adding this line, or we can change the starting_notebook.ipynb. And I prefer the former over the latter. Because I always wondering why Episode 4 begin with Editing function to our package when there is no editing to the function. I believe that it was originally intended for an introduction to function editing. And that is why there is a module check to see what is the content of symbols and coords variables, then the output of symbols variable is... Numpy array!

Therefore I suggest that we add a little bit of introduction to function editing in Editing function to our package to teach the student how to change the function and how the change reflected when we're using the code. And the example that we use is adding the symbols = np.array(symbols) line to open_pdb.

radifar avatar Jun 21 '20 01:06 radifar