Learn with Cheminformatics NumPy

Introduction

Following Python class learned by chemoinformatics, it is one of the representative libraries of Python with the theme of lipidomics (exhaustive analysis of lipids). I will explain about "NumPy". We will mainly explain practical examples of chemoinformatics, so if you want to check the basics, please read the following article before reading this article.

Pharmaceutical researcher summarized NumPy

Basic operations using NumPy

By using NumPy, you can perform vector and matrix operations at high speed.

First, you can load the library with ʻimport library name. Furthermore, by adding ʻas abbreviation, you can call (point to) the library with the abbreviation written here. In the case of NumPy, it is customary to use np.

import numpy as np


masses = np.array([12, 1.00783, 15.99491]) #An ndarray containing the precise masses of carbon, hydrogen, and oxygen atoms
numbers = np.array([16, 32, 2]) #Number of carbon, hydrogen and oxygen atoms in palmitic acid

print(masses * numbers) #Calculate precision mass for each element
print(sum((masses * numbers))) #Precision mass of palmitic acid

As shown above, you can create a vector with multiple elements by doing np.array (list). When you perform four arithmetic operations, the operation is performed for each element. You can also use sum to find the sum of all the elements.

Difference from list

The vector created by np.array (list) is very similar to a list, but the data type is numpy.ndarray instead of list. Multiplying numpy.ndarrays will return numpy.ndarray multiplied by each element, but multiplying lists will result in TypeError and the operation cannot be performed.

import numpy as np


masses_ndarray = np.array([12, 1.00783, 15.99491])
print(type(masses_ndarray)) # numpy.ndarray

masses_list = [12, 1.00783, 15.99491]
print(type(masses_list)) # list

print(list(masses_ndarray)) # [12, 1.00783, 15.99491]

numbers_list = [16, 32, 2]
# print(masses_list * numbers_list) # TypeError

Application: Atomic weight calculation

Next, consider finding the atomic weight based on the precise mass of the atom and its isotope and the natural abundance ratio.

import numpy as np


exact_mass_H = np.array([1.00783, 2.01410]) #Precision isotope mass
isotope_ratio_H = np.array([0.99989, 0.00011]) #Natural abundance of isotopes

molecular_weight_H = sum(exact_mass_H * isotope_ratio_H) #Calculate atomic weight
print(molecular_weight_H) #Atomic weight of hydrogen

Application: Calculation of precise mass of multiple compounds

Finally, let's find the precise masses of multiple fatty acid molecular species.

import numpy as np


numbers = np.array([[16, 32, 2], [18, 36, 2], [18, 34, 2]]) #Elemental composition of palmitic acid, stearic acid, oleic acid

print(masses * numbers) #Calculate the precise mass of each element of each molecular species
print(np.sum(masses * numbers, axis=1)) #Calculate the precise mass of each molecular species

Summary

Here, I explained about NumPy, focusing on practical knowledge that can be used in chemoinformatics. Let's review the main points again.

--By using NumPy, you can easily perform operations between vector elements. --Can be used to calculate atomic weight, molecular weight, and precise mass.

Next, I will explain about Pandas in the following article.

Pandas learning from chemoinformatics

Reference materials / links

What is the programming language Python? Can it be used for AI and machine learning?

Recommended Posts

Learn with Cheminformatics NumPy
Learn Pandas with Cheminformatics
Learn with Cheminformatics Matplotlib
Learn Python with ChemTHEATER
Learn Zundokokiyoshi with LSTM
Moving average with numpy
Learn with chemoinformatics scikit-learn
Getting Started with Numpy
Matrix concatenation with Numpy
Hamming code with numpy
DCGAN with TF Learn
Regression analysis with NumPy
Extend NumPy with Rust
Learn Pendulum-v0 with DDPG
Kernel regression with Numpy only
I wrote GP with numpy
CNN implementation with just numpy
Artificial data generation with numpy
Try matrix operation with NumPy
Diffusion equation animation with NumPy
Debt repayment simulation with numpy
Implemented SMO with Python + NumPy
Stick strings together with Numpy
Learn new data with PaintsChainer
Handle numpy arrays with f2py
Use OpenBLAS with numpy, scipy
Python Iteration Learning with Cheminformatics
Python3 | Getting Started with numpy
Implementing logistic regression with NumPy
Learn algorithms with Go @ recursive call
Perform least squares fitting with numpy.
Learn with Causal ML Package Meta-Learner
Learn with FizzBuzz Iterator, Generator, Decorator
Learn with PyTorch Graph Convolutional Networks
[TensorFlow 2] Learn RNN with CTC Loss
Let's learn Deep SEA with Selene
Draw a beautiful circle with numpy
Learn document categorization with spaCy CLI
Implement Keras LSTM feedforward with numpy
Extract multiple elements with Numpy array
Getting Started with python3 # 1 Learn Basic Knowledge
Learn to colorize monochrome images with Chainer
Learn data distributed with TensorFlow Y = 2X
Read and write csv files with numpy
Create bins with NumPy, get data-bin correspondence
Learn Python! Comparison with Java (basic function)
Learn with Splatoon nervous breakdown! Graph theory
"How to pass PATH" to learn with homebrew
Graph trigonometric functions with numpy and matplotlib
I made a life game with Numpy
Learn the design pattern "Singleton" with Python
Read a character data file with numpy
Handle numpy with Cython (method by memoryview)
Use multithreaded BLAS / LAPACK with numpy / scipy
Preparing to learn technical indicators with TFlearn
Learn the design pattern "Facade" with Python