text:
\chapter{Going 3D: The PDB module}

Bio.PDB is a Biopython module that focuses on working with crystal structures of biological macromolecules. Among other things, Bio.PDB includes a PDBParser class that produces a Structure object, which can be used to access the atomic data in the file in a convenient manner. There is limited support for parsing the information contained in the PDB header. PDB file format is no longer being modified or extended to support new content and PDBx/mmCIF became the standard PDB archive format in 2014. All the Worldwide Protein Data Bank (wwPDB) sites uses the macromolecular Crystallographic Information File (mmCIF) data dictionaries to describe the information content of PDB entries. mmCIF uses a flexible and extensible key-value pair format for representing macromolecular structural data and imposes no limitations for the number of atoms, residues or chains that can be represented in a single PDB entry (no split entries!).

%Note the \verb|Bio.PDB| module requires Numerical Python (numpy) to be installed.

\section{Reading and writing crystal structure files}

\subsection{Reading an mmCIF file}

Similarly to the case of PDB files, first create an \texttt{MMCIFParser} object:

\begin{minted}{pycon}
>>> from Bio.PDB.MMCIFParser import MMCIFParser
>>> parser = MMCIFParser()
\end{minted}
Then use this parser to create a structure object from the mmCIF file:
\begin{minted}{pycon}
>>> structure = parser.get_structure("1fat", "1fat.cif")
\end{minted}

To have some more low level access to an mmCIF file, you can use the \verb+MMCIF2Dict+ class to create a Python dictionary that maps all mmCIF
tags in an mmCIF file to their values. If there are multiple values
(like in the case of tag \verb+_atom_site.Cartn_y+, which holds
the $y$ coordinates of all atoms), the tag is mapped to a list of values.
The dictionary is created from the mmCIF file as follows:

\begin{minted}{pycon}
>>> from Bio.PDB.MMCIF2Dict import MMCIF2Dict
>>> mmcif_dict = MMCIF2Dict("1FAT.cif")
\end{minted}

Example: get the solvent content from an mmCIF file:
\begin{minted}{pycon}
>>> sc = mmcif_dict["_exptl_crystal.density_percent_sol"]
\end{minted}

Example: get the list of the $y$ coordinates of all atoms
\begin{minted}{pycon}
>>> y_list = mmcif_dict["_atom_site.Cartn_y"]
\end{minted}

\subsection{Reading files in the MMTF format}

You can use the direct MMTFParser to read a structure from a file:
%want to use doctest ../Tests lib:mmtf
%but will trigger PDBConstructionWarning
\begin{minted}{pycon}
>>> from Bio.PDB.mmtf import MMTFParser
>>> structure = MMTFParser.get_structure("PDB/4CUP.mmtf")
\end{minted}

Or you can use the same class to get a structure by its PDB ID:
%want online doctest here
\begin{minted}{pycon}
>>> structure = MMTFParser.get_structure_from_url("4CUP")
\end{minted}

This gives you a Structure object as if read from a PDB or mmCIF file.

You can also have access to the underlying data using the external
MMTF library which Biopython is using internally:
%want online doctest here
\begin{minted}{pycon}
>>> from mmtf import fetch
>>> decoded_data = fetch("4CUP")
\end{minted}
For example you can access just the X-coordinate.
\begin{minted}{pycon}
>>> print(decoded_data.x_coord_list)
...
\end{minted}

\subsection{Reading a PDB file}

First we create a \texttt{PDBParser} object:

\begin{minted}{pycon}
>>> from Bio.PDB.PDBParser import PDBParser
>>> parser = PDBParser(PERMISSIVE=1)
\end{minted}

The {\tt PERMISSIVE} flag indicates that a number of common problems (see \ref{problem structures}) associated with PDB files will be ignored (but note that some atoms and/or residues will be missing). If the flag is not present a {\tt PDBConstructionException} will be generated if any problems are detected during the parse operation.

The Structure object is then produced by letting the \texttt{PDBParser} object parse a PDB file (the PDB file in this case is called \verb|pdb1fat.ent|, \verb|1fat| is a user defined name for the structure):

\begin{minted}{pycon}
>>> structure_id = "1fat"
>>> filename = "pdb1fat.ent"
>>> structure = parser.get_structure(structure_id, filename)
\end{minted}

You can extract the header and trailer (simple lists of strings) of the PDB
file from the PDBParser object with the {\tt get\_header} and {\tt get\_trailer}
methods.  Note however that many PDB files contain headers with
incomplete or erroneous information. Many of the errors have been
fixed in the equivalent mmCIF files. \emph{Hence, if you are interested
in the header information, it is a good idea to extract information
from mmCIF files using the} \texttt{\emph{MMCIF2Dict}} \emph{tool
described below, instead of parsing the PDB header. }

Now that is clarified, let's return to parsing the PDB header. The
structure object has an attribute called \texttt{header} which is
a Python dictionary that maps header records to their values.

Example:

\begin{minted}{pycon}
>>> resolution = structure.header["resolution"]
>>> keywords = structure.header["keywords"]
\end{minted}
The available keys are \verb+name+, \verb+head+, \verb+deposition_date+,
\verb+release_date+, \verb+structure_method+, \verb+resolution+,
\verb+structure_reference+ (which maps to a list of references),
\verb+journal_reference+, \verb+author+, \verb+compound+ (which maps to a dictionary with various information about the crystallized compound),
\verb+has_missing_residues+, and \verb+missing_residues+.

\verb+has_missing_residues+ maps to a bool that is True if at least
one non-empty \verb+REMARK 465+ header line was found. In this case
you should assume that the molecule used in the experiment has some
residues for which no ATOM coordinates could be determined.
\verb+missing_residues+ maps to a list of dictionaries with information
about the missing residues. \emph{The list of missing residues will be
empty or incomplete if the PDB header does not follow the template from
the PDB specification.}

The dictionary can also be created without creating a \texttt{Structure}
object, ie. directly from the PDB file:

\begin{minted}{pycon}
>>> from Bio.PDB import parse_pdb_header
>>> with open(filename, "r") as handle:
...     header_dict = parse_pdb_header(handle)
...
\end{minted}

\subsection{Reading files in the PDB XML format}

That's not yet supported, but we are definitely planning to support that
in the future (it's not a lot of work). Contact the Biopython developers
via the mailing list if you need this.

\subsection{Writing mmCIF files}

A similar interface can be used to write structures to the mmCIF file format:

\begin{minted}{pycon}
>>> io = MMCIFIO()
>>> io.set_structure(s)
>>> io.save("out.cif")
\end{minted}
The \texttt{Select} class can be used in a similar way to \texttt{PDBIO} above.
mmCIF dictionaries read using \texttt{MMCIF2Dict} can also be written:

\begin{minted}{pycon}
>>> io = MMCIFIO()
>>> io.set_dict(d)
>>> io.save("out.cif")
\end{minted}

\subsection{Writing PDB files}

Use the PDBIO class for this. It's easy to write out specific parts
of a structure too, of course.

Example: saving a structure

\begin{minted}{pycon}
>>> io = PDBIO()
>>> io.set_structure(s)
>>> io.save("out.pdb")
\end{minted}
If you want to write out a part of the structure, make use of the
\texttt{Select} class (also in \texttt{PDBIO}). Select has four methods:

\begin{itemize}
\item \verb+accept_model(model)+
\item \verb+accept_chain(chain)+
\item \verb+accept_residue(residue)+
\item \verb+accept_atom(atom)+
\end{itemize}
By default, every method returns 1 (which means the model/\-chain/\-residue/\-atom
is included in the output). By subclassing \texttt{Select} and returning
0 when appropriate you can exclude models, chains, etc. from the output.
Cumbersome maybe, but very powerful. The following code only writes
out glycine residues:

\begin{minted}{pycon}
>>> class GlySelect(Select):
...     def accept_residue(self, residue):
...         if residue.get_name()=="GLY":
...             return True
...         else:
...             return False
...
>>> io = PDBIO()
>>> io.set_structure(s)
>>> io.save("gly_only.pdb", GlySelect())
\end{minted}
If this is all too complicated for you, the \texttt{Dice} module contains
a handy \texttt{extract} function that writes out all residues in
a chain between a start and end residue.

\section{Structure representation}

The overall layout of a \texttt{Structure} object follows the so-called SMCRA
(Structure/Model/Chain/Residue/Atom) architecture:

\begin{itemize}
\item A structure consists of models
\item A model consists of chains
\item A chain consists of residues
\item A residue consists of atoms
\end{itemize}
This is the way many structural biologists/bioinformaticians think
about structure, and provides a simple but efficient way to deal with
structure. Additional stuff is essentially added when needed. A UML
diagram of the \texttt{Structure} object (forget about the \texttt{Disordered}
classes for now) is shown in Fig. \ref{fig:smcra}. Such a data structure is not
necessarily best suited for the representation of the macromolecular content of
a structure, but it is absolutely necessary for a good interpretation of the
data present in a file that describes the structure (typically a PDB or MMCIF
file). If this hierarchy cannot represent the contents of a structure file, it
is fairly certain that the file contains an error or at least does not describe
the structure unambiguously. If a SMCRA data structure cannot be generated,
there is reason to suspect a problem. Parsing a PDB file can thus be used to
detect likely problems. We will give several examples of this in section
\ref{problem structures}.

\begin{figure}[htbp]
\begin{htmlonly}
\imgsrc[width=650, height=750]{images/smcra.png}
\end{htmlonly}
\begin{latexonly}
\centering
\includegraphics[width=0.8\textwidth]{images/smcra.png}
\end{latexonly}
\caption{UML diagram of SMCRA architecture of the \texttt{Structure} class used to represent a macromolecular structure.
Full lines with diamonds denote aggregation, full lines with
arrows denote referencing, full lines with triangles denote inheritance
and dashed lines with triangles denote interface realization.}
\label{fig:smcra}
\end{figure}

Structure, Model, Chain and Residue are all subclasses of the Entity base class.
The Atom class only (partly) implements the Entity interface (because an Atom
does not have children).

For each Entity subclass, you can extract a child by using a unique id for that
child as a key (e.g. you can extract an Atom object from a Residue object by
using an atom name string as a key, you can extract a Chain object from a Model
object by using its chain identifier as a key).

Disordered atoms and residues are represented by DisorderedAtom and DisorderedResidue
classes, which are both subclasses of the DisorderedEntityWrapper base class.
They hide the complexity associated with disorder and behave exactly as Atom
and Residue objects.

In general, a child Entity object (i.e. Atom, Residue, Chain, Model) can be
extracted from its parent (i.e. Residue, Chain, Model, Structure, respectively)
by using an id as a key.

\begin{minted}{pycon}
>>> child_entity = parent_entity[child_id]
\end{minted}

You can also get a list of all child Entities of a parent Entity object. Note
that this list is sorted in a specific way (e.g. according to chain identifier
for Chain objects in a Model object).

\begin{minted}{pycon}
>>> child_list = parent_entity.get_list()
\end{minted}

You can also get the parent from a child:
\begin{minted}{pycon}
>>> parent_entity = child_entity.get_parent()
\end{minted}

At all levels of the SMCRA hierarchy, you can also extract a \emph{full id}.
The full id is a tuple containing all id's starting from the top object (Structure)
down to the current object. A full id for a Residue object e.g. is something
like:

\begin{minted}{pycon}
>>> full_id = residue.get_full_id()
>>> print(full_id)
("1abc", 0, "A", ("", 10, "A"))
\end{minted}

This corresponds to:

\begin{itemize}
\item The Structure with id \char`\"{}1abc\char`\"{}
\item The Model with id 0
\item The Chain with id \char`\"{}A\char`\"{}
\item The Residue with id (\char`\"{} \char`\"{}, 10, \char`\"{}A\char`\"{}).
\end{itemize}
The Residue id indicates that the residue is not a hetero-residue (nor a water)
because it has a blank hetero field, that its sequence identifier is 10 and
that its insertion code is \char`\"{}A\char`\"{}.

To get the entity's id, use the \verb+get_id+ method:
\begin{minted}{pycon}
>>> entity.get_id()
\end{minted}
You can check if the entity has a child with a given id by using the \verb+has_id+ method:
\begin{minted}{pycon}
>>> entity.has_id(entity_id)
\end{minted}
The length of an entity is equal to its number of children:
\begin{minted}{pycon}
>>> nr_children = len(entity)
\end{minted}

It is possible to delete, rename, add, etc. child entities from a parent entity,
but this does not include any sanity checks (e.g. it is possible to add two
residues with the same id to one chain). This really should be done via a nice
Decorator class that includes integrity checking, but you can take a look at
the code (Entity.py) if you want to use the raw interface.

\subsection{Structure}

The Structure object is at the top of the hierarchy. Its id is a user given
string. The Structure contains a number of Model children. Most crystal structures
(but not all) contain a single model, while NMR structures typically consist
of several models. Disorder in crystal structures of large parts of molecules
can also result in several models.

\subsection{Model}

The id of the Model object is an integer, which is derived from the position
of the model in the parsed file (they are automatically numbered starting from
0).
Crystal structures generally have only one model (with id 0), while NMR files usually have several models. Whereas many PDB parsers assume that there is only one model, the \verb+Structure+ class in \verb+Bio.PDB+ is designed such that it can easily handle PDB files with more than one model.

As an example, to get the first model from a Structure object, use
\begin{minted}{pycon}
>>> first_model = structure[0]
\end{minted}

The Model object stores a list of Chain children.

\subsection{Chain}

The id of a Chain object is derived from the chain identifier in the PDB/mmCIF
file, and is a single character (typically a letter). Each Chain in a Model object has a unique id. As an example, to get the Chain object with identifier ``A'' from a Model object, use
\begin{minted}{pycon}
>>> chain_A = model["A"]
\end{minted}

The Chain object stores a list of Residue children.

\subsection{Residue}

A residue id is a tuple with three elements:

\begin{itemize}
\item The \textbf{hetero-field} (hetfield): this is
    \begin{itemize}
    \item \verb+'W'+ in the case of a water molecule;
    \item \verb+'H_'+ followed by the residue name for other hetero residues (e.g. \verb+'H_GLC'+ in the case of a glucose molecule);
    \item blank for standard amino and nucleic acids.
    \end{itemize}
This scheme is adopted for reasons described in section \ref{hetero problems}.
\item The \textbf{sequence identifier} (resseq), an integer describing the position of the residue in the chain (e.g., 100);
\item The \textbf{insertion code} (icode); a string, e.g. 'A'. The insertion code is sometimes used to preserve a certain desirable residue numbering scheme. A Ser 80 insertion mutant (inserted e.g. between a Thr 80 and an Asn 81
residue) could e.g. have sequence identifiers and insertion codes
as follows: Thr 80 A, Ser 80 B, Asn 81. In this way the residue numbering
scheme stays in tune with that of the wild type structure.
\end{itemize}
The id of the above glucose residue would thus be \texttt{('H\_GLC',
100, 'A')}. If the hetero-flag and insertion code are blank, the sequence
identifier alone can be used:

\begin{minted}{pycon}
# Full id
>>> residue=chain[(" ", 100, " ")]
# Shortcut id
>>> residue=chain[100]
\end{minted}
The reason for the hetero-flag is that many, many PDB files use the
same sequence identifier for an amino acid and a hetero-residue or
a water, which would create obvious problems if the hetero-flag was
not used.

Unsurprisingly, a Residue object stores a set of Atom children. It also contains a string that specifies the residue name (e.g. ``ASN'')
and the segment identifier of the residue (well known to X-PLOR users, but not
used in the construction of the SMCRA data structure).

Let's look at some examples. Asn 10 with a blank insertion code would have residue
id {\tt (' ', 10, ' ')}. Water 10 would have residue id {\tt ('W', 10, ' ')}.
A glucose molecule (a hetero residue with residue name GLC) with sequence identifier
10 would have residue id {\tt ('H\_GLC', 10, ' ')}. In this way, the three
residues (with the same insertion code and sequence identifier) can be part
of the same chain because their residue id's are distinct.

In most cases, the hetflag and insertion code fields will be blank, e.g. {\tt (' ', 10, ' ')}.
In these cases, the sequence identifier can be used as a shortcut for the full
id:

\begin{minted}{pycon}
# use full id
>>> res10 = chain[(" ", 10, " ")]
# use shortcut
>>> res10 = chain[10]
\end{minted}

Each Residue object in a Chain object should have a unique id. However, disordered
residues are dealt with in a special way, as described in section \ref{point mutations}.

A Residue object has a number of additional methods:

\begin{minted}{pycon}
>>> residue.get_resname()    # returns the residue name, e.g. "ASN"
>>> residue.is_disordered()  # returns 1 if the residue has disordered atoms
>>> residue.get_segid()      # returns the SEGID, e.g. "CHN1"
>>> residue.has_id(name)     # test if a residue has a certain atom
\end{minted}

You can use \texttt{is\_aa(residue)} to test if a Residue object is an amino acid.

\subsection{Atom}

The Atom object stores the data associated with an atom, and has no children.
The id of an atom is its atom name (e.g. ``OG'' for the side chain oxygen
of a Ser residue). An Atom id needs to be unique in a Residue. Again, an exception is made for disordered atoms, as described in section \ref{disordered atoms}.

The atom id is simply the atom name (eg. \texttt{'CA'}). In practice,
the atom name is created by stripping all spaces from the atom name
in the PDB file.

However, in PDB files, a space can be part of an atom name. Often,
calcium atoms are called \texttt{'CA..'} in order to distinguish them
from C$\alpha$ atoms (which are called \texttt{'.CA.'}). In cases
were stripping the spaces would create problems (ie. two atoms called
\texttt{'CA'} in the same residue) the spaces are kept.

In a PDB file, an atom name consists of 4 chars, typically with leading and
trailing spaces. Often these spaces can be removed for ease of use (e.g. an
amino acid C\( \alpha  \) atom is labeled ``.CA.'' in a PDB file, where
the dots represent spaces). To generate an atom name (and thus an atom id) the
spaces are removed, unless this would result in a name collision in a Residue
(i.e. two Atom objects with the same atom name and id). In the latter case,
the atom name including spaces is tried. This situation can e.g. happen when
one residue contains atoms with names ``.CA.'' and ``CA..'', although
this is not very likely.

The atomic data stored includes the atom name, the atomic coordinates (including
standard deviation if present), the B factor (including anisotropic B factors
and standard deviation if present), the altloc specifier and the full atom name
including spaces. Less used items like the atom element number or the atomic
charge sometimes specified in a PDB file are not stored.

To manipulate the atomic coordinates, use the \texttt{transform} method of
the \texttt{Atom} object. Use the \texttt{set\_coord} method to specify the
atomic coordinates directly.

An Atom object has the following additional methods:

\begin{minted}{pycon}
>>> a.get_name()       # atom name (spaces stripped, e.g. "CA")
>>> a.get_id()         # id (equals atom name)
>>> a.get_coord()      # atomic coordinates
>>> a.get_vector()     # atomic coordinates as Vector object
>>> a.get_bfactor()    # isotropic B factor
>>> a.get_occupancy()  # occupancy
>>> a.get_altloc()     # alternative location specifier
>>> a.get_sigatm()     # standard deviation of atomic parameters
>>> a.get_siguij()     # standard deviation of anisotropic B factor
>>> a.get_anisou()     # anisotropic B factor
>>> a.get_fullname()   # atom name (with spaces, e.g. ".CA.")
\end{minted}

To represent the atom coordinates, siguij, anisotropic B factor and sigatm Numpy
arrays are used.

The \texttt{get\_vector} method returns a \texttt{Vector} object representation of the coordinates of the \texttt{Atom} object, allowing you to do vector operations on atomic coordinates. \texttt{Vector} implements the full set of 3D vector operations, matrix multiplication (left and right) and some advanced rotation-related operations as well.

As an example of the capabilities of Bio.PDB's \texttt{Vector} module,
suppose that you would like to find the position of a Gly residue's C$\beta$
atom, if it had one. Rotating the N atom of
the Gly residue along the C$\alpha$-C bond over -120 degrees roughly
puts it in the position of a virtual C$\beta$ atom. Here's how to
do it, making use of the \texttt{rotaxis} method (which can be used
to construct a rotation around a certain axis) of the \texttt{Vector}
module:

\begin{minted}{pycon}
# get atom coordinates as vectors
>>> n = residue["N"].get_vector()
>>> c = residue["C"].get_vector()
>>> ca = residue["CA"].get_vector()
# center at origin
>>> n = n - ca
>>> c = c - ca
# find rotation matrix that rotates n
# -120 degrees along the ca-c vector
>>> rot = rotaxis(-pi * 120.0/180.0, c)
# apply rotation to ca-n vector
>>> cb_at_origin = n.left_multiply(rot)
# put on top of ca atom
>>> cb = cb_at_origin+ca
\end{minted}
This example shows that it's possible to do some quite nontrivial
vector operations on atomic data, which can be quite useful. In addition
to all the usual vector operations (cross (use \texttt{{*}{*}}), and
dot (use \texttt{{*}}) product, angle, norm, etc.) and the above mentioned
\texttt{rotaxis} function, the \texttt{Vector} module also has methods
to rotate (\texttt{rotmat}) or reflect (\texttt{refmat}) one vector
on top of another.

\subsection{Extracting a specific \texttt{Atom/\-Residue/\-Chain/\-Model}
from a Structure}

These are some examples:

\begin{minted}{pycon}
>>> model = structure[0]
>>> chain = model["A"]
>>> residue = chain[100]
>>> atom = residue["CA"]
\end{minted}
Note that you can use a shortcut:

\begin{minted}{pycon}
>>> atom = structure[0]["A"][100]["CA"]
\end{minted}

\section{Disorder}

Bio.PDB can handle both disordered atoms and point mutations (i.e. a
Gly and an Ala residue in the same position).

\subsection{General approach\label{disorder problems}}

Disorder should be dealt with from two points of view: the atom and the residue
points of view. In general, we have tried to encapsulate all the complexity that
arises from disorder. If you just want to loop over all C$\alpha$ atoms,
you do not care that some residues have a disordered side chain. On the other
hand it should also be possible to represent disorder completely in the data
structure. Therefore, disordered atoms or residues are stored in special objects
that behave as if there is no disorder. This is done by only representing a
subset of the disordered atoms or residues. Which subset is picked (e.g. which
of the two disordered OG side chain atom positions of a Ser residue is used)
can be specified by the user.

\subsection{Disordered atoms\label{disordered atoms}}

Disordered atoms are represented by ordinary \texttt{Atom} objects, but
all \texttt{Atom} objects that represent the same physical atom are stored
in a \texttt{Disordered\-Atom} object (see Fig. \ref{fig:smcra}).
Each \texttt{Atom} object in a \texttt{Disordered\-Atom} object can
be uniquely indexed using its altloc specifier. The \texttt{Disordered\-Atom}
object forwards all uncaught method calls to the selected Atom object,
by default the one that represents the atom with the highest
occupancy. The user can of course change the selected \texttt{Atom}
object, making use of its altloc specifier. In this way atom disorder
is represented correctly without much additional complexity. In other
words, if you are not interested in atom disorder, you will not be
bothered by it.

Each disordered atom has a characteristic altloc identifier. You can
specify that a \texttt{Disordered\-Atom} object should behave like
the \texttt{Atom} object associated with a specific altloc identifier:

\begin{minted}{pycon}
>>> atom.disordered_select("A") # select altloc A atom
>>> print(atom.get_altloc())
"A"
>>> atom.disordered_select("B") # select altloc B atom
>>> print(atom.get_altloc())
"B"
\end{minted}

\subsection{Disordered residues}

\subsubsection*{Common case}

The most common case is a residue that contains one or more disordered atoms.
This is evidently solved by using DisorderedAtom objects to represent the disordered
atoms, and storing the DisorderedAtom object in a Residue object just like ordinary
Atom objects. The DisorderedAtom will behave exactly like an ordinary atom (in
fact the atom with the highest occupancy) by forwarding all uncaught method
calls to one of the Atom objects (the selected Atom object) it contains.

\subsubsection*{Point mutations\label{point mutations}}

A special case arises when disorder is due to a point mutation, i.e. when two
or more point mutants of a polypeptide are present in the crystal. An example
of this can be found in PDB structure 1EN2.

Since these residues belong to a different residue type (e.g. let's
say Ser 60 and Cys 60) they should not be stored in a single \texttt{Residue}
object as in the common case. In this case, each residue is represented
by one \texttt{Residue} object, and both \texttt{Residue} objects
are stored in a single \texttt{Disordered\-Residue} object (see Fig.
\ref{fig:smcra}).

The \texttt{Dis\-ordered\-Residue} object forwards all un\-caught methods to
the selected \texttt{Residue} object (by default the last \texttt{Residue}
object added), and thus behaves like an ordinary residue. Each
\texttt{Residue} object in a \texttt{Disordered\-Residue} object can be
uniquely identified by its residue name. In the above example, residue Ser 60
would have id ``SER'' in the \texttt{Disordered\-Residue} object, while
residue Cys 60 would have id ``CYS''. The user can select the active
\texttt{Residue} object in a \texttt{Disordered\-Residue} object via this id.

Example: suppose that a chain has a point mutation at position 10,
consisting of a Ser and a Cys residue. Make sure that residue 10 of
this chain behaves as the Cys residue.
\begin{minted}{pycon}
>>> residue = chain[10]
>>> residue.disordered_select("CYS")
\end{minted}
In addition, you can get a list of all \texttt{Atom} objects (ie.
all \texttt{DisorderedAtom} objects are 'unpacked' to their individual
\texttt{Atom} objects) using the \texttt{get\_unpacked\_list} method
of a \texttt{(Disordered)\-Residue} object.

\section{Hetero residues}

\subsection{Associated problems\label{hetero problems}}

A common problem with hetero residues is that several hetero and non-hetero
residues present in the same chain share the same sequence identifier (and insertion
code). Therefore, to generate a unique id for each hetero residue, waters and
other hetero residues are treated in a different way.

Remember that Residue object have the tuple (hetfield, resseq, icode) as id.
The hetfield is blank (`` '') for amino and nucleic acids, and a string
for waters and other hetero residues. The content of the hetfield is explained
below.

\subsection{Water residues}

The hetfield string of a water residue consists of the letter ``W''. So
a typical residue id for a water is (``W'', 1, `` '').

\subsection{Other hetero residues}

The hetfield string for other hetero residues starts with ``H\_'' followed
by the residue name. A glucose molecule e.g. with residue name ``GLC''
would have hetfield ``H\_GLC''. Its residue id could e.g. be (``H\_GLC'',
1, `` '').

\section{Navigating through a Structure object}

\subsubsection*{Parse a PDB file, and extract some Model, Chain, Residue and Atom objects}

\begin{minted}{pycon}
>>> from Bio.PDB.PDBParser import PDBParser
>>> parser = PDBParser()
>>> structure = parser.get_structure("test", "1fat.pdb")
>>> model = structure[0]
>>> chain = model["A"]
>>> residue = chain[1]
>>> atom = residue["CA"]
\end{minted}

\subsubsection*{Iterating through all atoms of a structure}

\begin{minted}{pycon}
>>> p = PDBParser()
>>> structure = p.get_structure("X", "pdb1fat.ent")
>>> for model in structure:
...     for chain in model:
...         for residue in chain:
...             for atom in residue:
...                 print(atom)
...
\end{minted}

There is a shortcut if you want to iterate over all atoms in a structure:
\begin{minted}{pycon}
>>> atoms = structure.get_atoms()
>>> for atom in atoms:
...     print(atom)
...
\end{minted}

Similarly, to iterate over all atoms in a chain, use
\begin{minted}{pycon}
>>> atoms = chain.get_atoms()
>>> for atom in atoms:
...     print(atom)
...
\end{minted}

\subsubsection*{Iterating over all residues of a model}

or if you want to iterate over all residues in a model:
\begin{minted}{pycon}
>>> residues = model.get_residues()
>>> for residue in residues:
...     print(residue)
...
\end{minted}

You can also use the \verb+Selection.unfold_entities+ function to get all residues from a structure:
\begin{minted}{pycon}
>>> res_list = Selection.unfold_entities(structure, "R")
\end{minted}
or to get all atoms from a chain:
\begin{minted}{pycon}
>>> atom_list = Selection.unfold_entities(chain, "A")
\end{minted}
Obviously, \verb+A=atom, R=residue, C=chain, M=model, S=structure+.
You can use this to go up in the hierarchy, e.g. to get a list of
(unique) \verb+Residue+ or \verb+Chain+ parents from a list of
\verb+Atoms+:

\begin{minted}{pycon}
>>> residue_list = Selection.unfold_entities(atom_list, "R")
>>> chain_list = Selection.unfold_entities(atom_list, "C")
\end{minted}
For more info, see the API documentation.

\subsubsection*{Extract a hetero residue from a chain (e.g. a glucose (GLC) moiety with resseq 10)}

\begin{minted}{pycon}
>>> residue_id = ("H_GLC", 10, " ")
>>> residue = chain[residue_id]
\end{minted}

\subsubsection*{Print all hetero residues in chain}

\begin{minted}{pycon}
>>> for residue in chain.get_list():
...    residue_id = residue.get_id()
...    hetfield = residue_id[0]
...    if hetfield[0]=="H":
...        print(residue_id)
...
\end{minted}

\subsubsection*{Print out the coordinates of all CA atoms in a structure with B factor greater than 50}

\begin{minted}{pycon}
>>> for model in structure.get_list():
...     for chain in model.get_list():
...         for residue in chain.get_list():
...             if residue.has_id("CA"):
...                 ca = residue["CA"]
...                 if ca.get_bfactor() > 50.0:
...                     print(ca.get_coord())
...
\end{minted}

\subsubsection*{Print out all the residues that contain disordered atoms}

\begin{minted}{pycon}
>>> for model in structure.get_list():
...     for chain in model.get_list():
...         for residue in chain.get_list():
...             if residue.is_disordered():
...                 resseq = residue.get_id()[1]
...                 resname = residue.get_resname()
...                 model_id = model.get_id()
...                 chain_id = chain.get_id()
...                 print(model_id, chain_id, resname, resseq)
...
\end{minted}

\subsubsection*{Loop over all disordered atoms, and select all atoms with altloc A (if present)}
This will make sure that the SMCRA data structure will behave as if only the
atoms with altloc A are present.

\begin{minted}{pycon}
>>> for model in structure.get_list():
...     for chain in model.get_list():
...         for residue in chain.get_list():
...             if residue.is_disordered():
...                 for atom in residue.get_list():
...                     if atom.is_disordered():
...                         if atom.disordered_has_id("A"):
...                             atom.disordered_select("A")
...
\end{minted}

\subsubsection*{Extracting polypeptides from a \texttt{Structure} object\label{subsubsec:extracting_polypeptides}}

To extract polypeptides from a structure, construct a list of \texttt{Polypeptide} objects from a \texttt{Structure} object using \texttt{PolypeptideBuilder} as follows:

\begin{minted}{pycon}
>>> model_nr = 1
>>> polypeptide_list = build_peptides(structure, model_nr)
>>> for polypeptide in polypeptide_list:
...     print(polypeptide)
...
\end{minted}

A Polypeptide object is simply a UserList of Residue objects, and is always created from a single Model (in this case model 1).
You can use the resulting \texttt{Polypeptide} object to get the sequence as a \texttt{Seq} object or to get a list of C$\alpha$ atoms as well. Polypeptides can be built using a C-N or a C$\alpha$-C$\alpha$ distance criterion.

Example:

\begin{minted}{pycon}
# Using C-N
>>> ppb=PPBuilder()
>>> for pp in ppb.build_peptides(structure):
...     print(pp.get_sequence())
...
# Using CA-CA
>>> ppb=CaPPBuilder()
>>> for pp in ppb.build_peptides(structure):
...     print(pp.get_sequence())
...
\end{minted}
Note that in the above case only model 0 of the structure is considered
by \texttt{PolypeptideBuilder}. However, it is possible to use \texttt{PolypeptideBuilder}
to build \texttt{Polypeptide} objects from \texttt{Model} and \texttt{Chain}
objects as well.

\subsubsection*{Obtaining the sequence of a structure}

The first thing to do is to extract all polypeptides from the structure
(as above). The sequence of each polypeptide can then easily
be obtained from the \texttt{Polypeptide} objects. The sequence is
represented as a Biopython \texttt{Seq} object, and its alphabet is
defined by a \texttt{ProteinAlphabet} object.

Example:

\begin{minted}{pycon}
>>> seq = polypeptide.get_sequence()
>>> print(seq)
Seq('SNVVE...', <class Bio.Alphabet.ProteinAlphabet>)
\end{minted}

\section{Analyzing structures}

\subsection{Measuring distances}
The minus operator for atoms has been overloaded to return the distance between two atoms.
\begin{minted}{pycon}
# Get some atoms
>>> ca1 = residue1["CA"]
>>> ca2 = residue2["CA"]
# Simply subtract the atoms to get their distance
>>> distance = ca1-ca2
\end{minted}

\subsection{Measuring angles}
Use the vector representation of the atomic coordinates, and
the \texttt{calc\_angle} function from the \texttt{Vector} module:
\begin{minted}{pycon}
>>> vector1 = atom1.get_vector()
>>> vector2 = atom2.get_vector()
>>> vector3 = atom3.get_vector()
>>> angle = calc_angle(vector1, vector2, vector3)
\end{minted}

\subsection{Measuring torsion angles}
Use  the vector representation of the atomic coordinates, and
the \texttt{calc\_dihedral} function from the \texttt{Vector} module:
\begin{minted}{pycon}
>>> vector1 = atom1.get_vector()
>>> vector2 = atom2.get_vector()
>>> vector3 = atom3.get_vector()
>>> vector4 = atom4.get_vector()
>>> angle = calc_dihedral(vector1, vector2, vector3, vector4)
\end{minted}

\subsection{Determining atom-atom contacts}

Use \texttt{NeighborSearch} to perform neighbor lookup.
The neighbor lookup is done using a KD tree module written in C (see \texttt{Bio.KDTree}), making it very fast.
It  also includes a fast method to find all point pairs within a certain distance of each other.

\subsection{Superimposing two structures}

Use a \texttt{Superimposer} object to superimpose two coordinate sets.
This object calculates the rotation and translation matrix that rotates
two lists of atoms on top of each other in such a way that their RMSD
is minimized. Of course, the two lists need to contain the same number
of atoms. The \texttt{Superimposer} object can also apply the rotation/translation
to a list of atoms. The rotation and translation are stored as a tuple
in the \texttt{rotran} attribute of the \texttt{Superimposer} object
(note that the rotation is right multiplying!). The RMSD is stored
in the \texttt{rmsd} attribute.

The algorithm used by \texttt{Superimposer} comes from \cite[Golub \& Van Loan]{golub1989} and makes use of singular value decomposition (this is implemented in the general \texttt{Bio.SVDSuperimposer} module).

Example:

\begin{minted}{pycon}
>>> sup = Superimposer()
# Specify the atom lists
# 'fixed' and 'moving' are lists of Atom objects
# The moving atoms will be put on the fixed atoms
>>> sup.set_atoms(fixed, moving)
# Print rotation/translation/rmsd
>>> print(sup.rotran)
>>> print(sup.rms)
# Apply rotation/translation to the moving atoms
>>> sup.apply(moving)
\end{minted}

To superimpose two structures based on their active sites, use the active site atoms to calculate the rotation/translation matrices (as above), and apply these to the whole molecule.

\subsection{Mapping the residues of two related structures onto each other}

First, create an alignment file in FASTA format, then use the \texttt{StructureAlignment}
class. This class can also be used for alignments with more than two
structures.

\subsection{Calculating the Half Sphere Exposure}

Half Sphere Exposure (HSE) is a new, 2D measure of solvent exposure
\cite{hamelryck2005}.
Basically, it counts the number of C$\alpha$ atoms around a residue
in the direction of its side chain, and in the opposite direction
(within a radius of $13 \AA$). Despite its simplicity, it outperforms
many other measures of solvent exposure.

HSE comes in two flavors: HSE$\alpha$ and HSE$\beta$. The former
only uses the C$\alpha$ atom positions, while the latter uses the
C$\alpha$ and C$\beta$ atom positions. The HSE measure is calculated
by the \texttt{HSExposure} class, which can also calculate the contact
number. The latter class has methods which return dictionaries that
map a \texttt{Residue} object to its corresponding HSE$\alpha$, HSE$\beta$
and contact number values.

Example:

\begin{minted}{pycon}
>>> model = structure[0]
>>> hse = HSExposure()
# Calculate HSEalpha
>>> exp_ca = hse.calc_hs_exposure(model, option="CA3")
# Calculate HSEbeta
>>> exp_cb=hse.calc_hs_exposure(model, option="CB")
# Calculate classical coordination number
>>> exp_fs = hse.calc_fs_exposure(model)
# Print HSEalpha for a residue
>>> print(exp_ca[some_residue])
\end{minted}

\subsection{Determining the secondary structure}

For this functionality, you need to install DSSP (and obtain a license
for it --- free for academic use, see \url{https://swift.cmbi.umcn.nl/gv/dssp/}).
Then use the \texttt{DSSP} class, which maps \texttt{Residue} objects
to their secondary structure (and accessible surface area). The DSSP
codes are listed in Table \ref{cap:DSSP-codes}. Note that DSSP (the
program, and thus by consequence the class) cannot handle multiple
models!

\begin{table}
\begin{tabular}{|c|c|}
\hline
Code&
Secondary structure \\
\hline
\hline
H&
$\alpha$-helix \\
\hline
B&
Isolated $\beta$-bridge residue \\
\hline
E&
Strand \\
\hline
G&
3-10 helix \\
\hline
I&
$\Pi$-helix \\
\hline
T&
Turn\\
\hline
S&
Bend \\
\hline
-&
Other\\
\hline
\end{tabular}
\caption{\label{cap:DSSP-codes}DSSP codes in Bio.PDB.}
\end{table}

The \texttt{DSSP} class can also be used to calculate the accessible surface area of a residue. But see also section \ref{subsec:residue_depth}.

\subsection{Calculating the residue depth\label{subsec:residue_depth}}

Residue depth is the average distance of a residue's atoms from the
solvent accessible surface. It's a fairly new and very powerful parameterization
of solvent accessibility. For this functionality, you need to install
Michel Sanner's MSMS program (\url{https://www.scripps.edu/sanner/html/msms_home.html}).
Then use the \texttt{ResidueDepth} class. This class behaves as a
dictionary which maps \texttt{Residue} objects to corresponding (residue
depth, C$\alpha$ depth) tuples. The C$\alpha$ depth is the distance
of a residue's C$\alpha$ atom to the solvent accessible surface.

Example:

\begin{minted}{pycon}
>>> model = structure[0]
>>> rd = ResidueDepth(model, pdb_file)
>>> residue_depth, ca_depth=rd[some_residue]
\end{minted}
You can also get access to the molecular surface itself (via the \texttt{get\_surface}
function), in the form of a Numeric Python array with the surface points.

\section{Common problems in PDB files}

It is well known that many PDB files contain semantic errors (not the
structures themselves, but their representation in PDB files).
Bio.PDB tries to handle this in two ways. The PDBParser
object can behave in two ways: a restrictive way and a permissive
way, which is the default.

Example:

\begin{minted}{pycon}
# Permissive parser
>>> parser = PDBParser(PERMISSIVE=1)
>>> parser = PDBParser() # The same (default)
# Strict parser
>>> strict_parser = PDBParser(PERMISSIVE=0)
\end{minted}
In the permissive state (DEFAULT), PDB files that obviously contain
errors are ``corrected'' (i.e. some residues or atoms are left out).
These errors include:

\begin{itemize}
\item Multiple residues with the same identifier
\item Multiple atoms with the same identifier (taking into account the altloc
identifier)
\end{itemize}
These errors indicate real problems in the PDB file (for details see
\cite[Hamelryck and Manderick, 2003]{hamelryck2003a}). In the restrictive state, PDB files with errors cause an exception to occur. This is useful to find errors in PDB files.

Some errors however are automatically corrected. Normally each disordered
atom should have a non-blank altloc identifier. However, there are
many structures that do not follow this convention, and have a blank
and a non-blank identifier for two disordered positions of the same
atom. This is automatically interpreted in the right way.

Sometimes a structure contains a list of residues belonging to chain
A, followed by residues belonging to chain B, and again followed by
residues belonging to chain A, i.e. the chains are 'broken'. This
is also correctly interpreted.

\subsection{Examples\label{problem structures}}

The PDBParser/Structure class was tested on about 800 structures (each belonging
to a unique SCOP superfamily). This takes about 20 minutes, or on average 1.5
seconds per structure. Parsing the structure of the large ribosomal subunit
(1FKK), which contains about 64000 atoms, takes 10 seconds on a 1000 MHz PC.

Three exceptions were generated in cases where an unambiguous data structure
could not be built. In all three cases, the likely cause is an error in the
PDB file that should be corrected. Generating an exception in these cases
is much better than running the chance of incorrectly describing
the structure in a data structure.

\subsubsection{Duplicate residues}

One structure contains two amino acid residues in one chain with the same sequence
identifier (resseq 3) and icode. Upon inspection it was found that this chain
contains the residues Thr A3, \ldots, Gly A202, Leu A3, Glu A204. Clearly,
Leu A3 should be Leu A203. A couple of similar situations exist for structure
1FFK (which e.g. contains Gly B64, Met B65, Glu B65, Thr B67, i.e. residue Glu
B65 should be Glu B66).

\subsubsection{Duplicate atoms}

Structure 1EJG contains a Ser/Pro point mutation in chain A at position 22.
In turn, Ser 22 contains some disordered atoms. As expected, all atoms belonging
to Ser 22 have a non-blank altloc specifier (B or C). All atoms of Pro 22 have
altloc A, except the N atom which has a blank altloc. This generates an exception,
because all atoms belonging to two residues at a point mutation should have
non-blank altloc. It turns out that this atom is probably shared by Ser and
Pro 22, as Ser 22 misses the N atom. Again, this points to a problem in the
file: the N atom should be present in both the Ser and the Pro residue, in both
cases associated with a suitable altloc identifier.

\subsection{Automatic correction}

Some errors are quite common and can be easily corrected without much risk of
making a wrong interpretation. These cases are listed below.

\subsubsection{A blank altloc for a disordered atom}

Normally each disordered atom should have a non-blank altloc identifier. However,
there are many structures that do not follow this convention, and have a blank
and a non-blank identifier for two disordered positions of the same atom. This
is automatically interpreted in the right way.

\subsubsection{Broken chains}

Sometimes a structure contains a list of residues belonging to chain A, followed
by residues belonging to chain B, and again followed by residues belonging to
chain A, i.e. the chains are ``broken''. This is correctly interpreted.

\subsection{Fatal errors}

Sometimes a PDB file cannot be unambiguously interpreted. Rather than guessing
and risking a mistake, an exception is generated, and the user is expected to
correct the PDB file. These cases are listed below.

\subsubsection{Duplicate residues}

All residues in a chain should have a unique id. This id is generated based
on:

\begin{itemize}
\item The sequence identifier (resseq).
\item The insertion code (icode).
\item The hetfield string (``W'' for waters and ``H\_'' followed by the
residue name for other hetero residues)
\item The residue names of the residues in the case of point mutations (to store the
Residue objects in a DisorderedResidue object).
\end{itemize}
If this does not lead to a unique id something is quite likely wrong, and an
exception is generated.

\subsubsection{Duplicate atoms}

All atoms in a residue should have a unique id. This id is generated based on:

\begin{itemize}
\item The atom name (without spaces, or with spaces if a problem arises).
\item The altloc specifier.
\end{itemize}
If this does not lead to a unique id something is quite likely wrong, and an
exception is generated.

\section{Accessing the Protein Data Bank}

\subsection{Downloading structures from the Protein Data Bank}

Structures can be downloaded from the PDB (Protein Data Bank)
by using the \texttt{retrieve\_pdb\_file} method on a \texttt{PDBList} object.
The argument for this method is the PDB identifier of the structure.

\begin{minted}{pycon}
>>> pdbl = PDBList()
>>> pdbl.retrieve_pdb_file("1FAT")
\end{minted}

The \texttt{PDBList} class can also be used as a command-line tool:
\begin{minted}{pycon}
python PDBList.py 1fat
\end{minted}
The downloaded file will be called \texttt{pdb1fat.ent} and stored
in the current working directory. Note that the \texttt{retrieve\_pdb\_file}
method also has an optional argument \texttt{pdir} that specifies
a specific directory in which to store the downloaded PDB files.

The \texttt{retrieve\_pdb\_file} method also has some options to specify
the compression format used for the download, and the program used
for local decompression (default \texttt{.Z} format and \texttt{gunzip}).
In addition, the PDB ftp site can be specified upon creation of the
\texttt{PDBList} object. By default, the server of the Worldwide Protein Data Bank (\url{ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/pdb/})
is used. See the API documentation for more details. Thanks again
to Kristian Rother for donating this module.

\subsection{Downloading the entire PDB}

The following commands will store all PDB files in the \texttt{/data/pdb}
directory:

\begin{minted}{pycon}
python PDBList.py all /data/pdb

python PDBList.py all /data/pdb -d
\end{minted}
\noindent The API method for this is called \texttt{download\_entire\_pdb}.
Adding the \texttt{-d} option will store all files in the same directory.
Otherwise, they are sorted into PDB-style subdirectories according
to their PDB ID's. Depending on the traffic, a complete download will
take 2-4 days.

\subsection{Keeping a local copy of the PDB up to date}

This can also be done using the \texttt{PDBList} object. One simply
creates a \texttt{PDBList} object (specifying the directory where
the local copy of the PDB is present) and calls the \texttt{update\_pdb}
method:

\begin{minted}{pycon}
>>> pl = PDBList(pdb="/data/pdb")
>>> pl.update_pdb()
\end{minted}
One can of course make a weekly \texttt{cronjob} out of this to keep
the local copy automatically up-to-date. The PDB ftp site can also
be specified (see API documentation).

\texttt{PDBList} has some additional methods that can be of use. The
\texttt{get\_all\_obsolete} method can be used to get a list of all
obsolete PDB entries. The \texttt{changed\_this\_week} method can
be used to obtain the entries that were added, modified or obsoleted
during the current week. For more info on the possibilities of \texttt{PDBList},
see the API documentation.

\section{General questions}

\subsection{How well tested is Bio.PDB?}

Pretty well, actually. Bio.PDB has been extensively tested on nearly
5500 structures from the PDB - all structures seemed to be parsed
correctly. More details can be found in the Bio.PDB Bioinformatics
article. Bio.PDB has been used/is being used in many research projects
as a reliable tool. In fact, I'm using Bio.PDB almost daily for research
purposes and continue working on improving it and adding new features.

\subsection{How fast is it?}

The \texttt{PDBParser} performance was tested on about 800 structures
(each belonging to a unique SCOP superfamily). This takes about 20
minutes, or on average 1.5 seconds per structure. Parsing the structure
of the large ribosomal subunit (1FKK), which contains about 64000
atoms, takes 10 seconds on a 1000 MHz PC. In short: it's more than
fast enough for many applications.

\subsection{Is there support for molecular graphics?}

Not directly, mostly since there are quite a few Python based/Python
aware solutions already, that can potentially be used with Bio.PDB.
My choice is Pymol, BTW (I've used this successfully with Bio.PDB,
and there will probably be specific PyMol modules in Bio.PDB soon/some
day). Python based/aware molecular graphics solutions include:

\begin{itemize}
\item PyMol: \url{https://pymol.org/}
\item Chimera: \url{https://www.cgl.ucsf.edu/chimera/}
\item PMV: \url{http://www.scripps.edu/~sanner/python/}
\item Coot: \url{https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/}
\item CCP4mg: \url{http://www.ccp4.ac.uk/MG/}
\item mmLib: \url{http://pymmlib.sourceforge.net/}
\item VMD: \url{https://www.ks.uiuc.edu/Research/vmd/}
\item MMTK: \url{http://dirac.cnrs-orleans.fr/MMTK/}
\end{itemize}

\subsection{Who's using Bio.PDB?}

Bio.PDB was used in the construction of DISEMBL, a web server that
predicts disordered regions in proteins (\url{http://dis.embl.de/}),
and COLUMBA, a website that provides annotated protein structures
(\url{http://www.columba-db.de/}). Bio.PDB has also been used to
perform a large scale search for active sites similarities between
protein structures in the PDB \cite[Hamelryck, 2003]{hamelryck2003b}, and to develop a new algorithm
that identifies linear secondary structure elements \cite[Majumdar \textit{et al.}, 2005]{majumdar2005}.

Judging from requests for features and information, Bio.PDB is also
used by several LPCs (Large Pharmaceutical Companies :-).

% Perhaps this section should be updated for other Biopython modules, and
% moved to the Biopython FAQ above.

max_stars_repo_name: tipabu/biopython

max_issues_repo_name: tipabu/biopython

max_forks_repo_name: tipabu/biopython


text:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{graphicx}
\title{CMSC426Pj1 Report}
\author{Yizhan Ao UID: 116022064}
\author{
  Yingqiao, Gou\\
  \texttt{ygou@terpmail.umd.edu}
  \texttt{UID:115979000}
  \and
  Yizhan, Ao\\
  \texttt{josephao@umd.edu}
  \texttt{UID:116022064}
}

\date{September 22nd 2021}

\begin{document}

\maketitle

\section{Introduction}
\begin{enumerate}
    \paragraphSingle-Gaussian and Gaussian-Mixture Models are utilized in various pattern recognition tasks. The model parameters are estimated usually via Maximum Likelihood Estimation (MLE) with respect to available training data. However, if only small amount of training data is available, the resulting model will not generalize well. Loosely speaking, classification performance given an unseen test set may be poor. In this paper, we propose a novel estimation technique of the model variances. Once the variances were estimated using MLE, they are multiplied by a scaling factor, which reflects the amount of uncertainty present in the limited sample set. The optimal value of the scaling factor is based on the Kullback-Leibler criterion and on the assumption that the training and test sets are sampled from the same source distribution. In addition, in the case of GMM, the proper number of components can be determined.
\end{enumerate}

\section{Single Gaussian}
The color segmentation we need probability of the orange pixel distribution in a picture the. In Single Gaussian Color segementation there are several steps that we need to follow.
\begin{enumerate}
    \item Read image
    \item Convert the image to the color space
    \item Check if the pixel is orange or not
    \item if the color threshold is orange then we collect these pixels and proceed
    \item If not we go back and redo the color and detect again on another picture.
    \item We calculate the mean and covariance and the likelihood and posterior so we can follow the Gaussian equation and have the value of $P(Cl|x)>=r$
    \item Mask the image
    \item train image from training set
    \item Train images from the testing set
\end{enumerate}
In order to find the probability distribution we need the likelihood of orange pixels of the picture. The idea is to collect all the orange pixels. Combining color thresholding and sigma to minimize the value of each color, using function $roipoly()$ we could identify the automation of clustering orange color
\begin{itemize}
    \item $P(C_1)$ we set this probability of the pixel of being orange and the possibility that is not orange is also 0.5
    \item The $posterior(C_l|x)$ is the probabilty that the pixel is orange or not orange
    \item \begin{equation}p(C_l \mid x)=\frac{p(x \mid C_l) * p(C_l)}{\sum_{i=1}^{l} p(x \mid Ci) p(C i)}\end{equation}
    \item Posterior is directly proportional towards prior and likelihood.
    \item The thresholding is $P(C_l|x)$ which the threshold need to be higher than the confidence level
    %\item
\end{itemize}
\includegraphics[scale = 0.3]{Fig1.jpg}
\includegraphics[scale = 0.3]{Fig2.jpg}
\includegraphics[scale = 0.3]{Fig3.jpg}
\includegraphics[scale = 0.3]{Fig4.jpg}
\includegraphics[scale = 0.3]{Fig5.jpg}
\includegraphics[scale = 0.3]{Fig6.jpg}
\includegraphics[scale = 0.3]{Fig7.jpg}
\includegraphics[scale = 0.3]{Fig8.jpg}
\textbf{Drawbacks}
\begin{itemize}
    \item Single Gaussian is very dependent from the user input. A slight change towards the training sample could make a very big difference towards the final output compared to the test set.
    \item Single Gaussian is also very relying on the lighting towards the object. We could see a big difference while running with a good lighting and bad lighting, This is also very dependent on the human input
\end{itemize}

\section{Gaussian Mixture Model}
\begin{itemize}
    \item We chose RGB-space, followed the module's instructions for randomized initialization, and used k = 10 for the number of Gaussians. The GMM algorithm is more powerful because it uses several gaussians to describe the colors in the orange ball training batch of pictures. There are variations in the natural world. even within a single image, the RGB color values of the ball These variations are not present in the single gaussian model. It must be accounted for solely by a single gaussian. This means that the covariance matrix for this is a single.
    \item We selected a threshold of .000008, slightly more lenient than the one usedfor SG. We chose it largely because of its performance on the testing set, but also because we felt that the larger K would be more resistant to lighting and thus less prone to false positives.
    \item Gaussian must strike a balance between mapping too high a probability to colors that aren't in the original and mapping too low a probability to colors that aren't in the original.

    \includegraphics[scale = 0.6]{GMM.png}
    \item There are two processes in short
        \begin{enumerate}
            \item Initialization: The mean was calculated at random using the matlab function rand. Covariance initialization was a little more difficult because it had to be positive semi definite. As a result, it was merely initialized by computing the cov of all the images(pixels x 3 dimension), elements, and ensuring that it was PSD and that its inverse existed.
            \item Number of gaussians in GMM: When it comes to the number of gaussians, there is an optimal number.The number of gaussians in our sample was fixed to seven. We can't fully capture the color space if the number of gaussians is low, so our method underfits and the accuracy is low. On the other hand, if the number of gaussians is increased, the algorithm tends to overfit, which may not be a good generalization. Overfitting will lead to poor prediction.
        \end{enumerate}

\end{itemize}
\section{Train Data }
    \begin{itemize}
        \item The same procedure is used to begin training and collect orange pixels as with a single gaussian. To get a rough idea of where the ball was, we employed the iterative technique of Maximum Likelihood Estimation.
        \item Covariance was set to the covariance of the orange pixels, while mu and pi were set to random values using MATLAB's rand function. Although not fully random as described in the project description, it was sufficiently random for its purpose and ensured a square, PSD matrix.
        \item We thought starting with the estimating stage and then alternated till we reached our pre-determined threshold. That could be a really good idea to achieve
    \end{itemize}
\section{Test Data}
    \item The normal process stated in the standards is followed when predicting from test results.The expected image, like Single Gaussian, is binary, with orange representing white and the rest being black. Each image is returned after being added to a cluster described by a cell array to allow for various sizes.
\section{Distance}
    \item The distance was implemented by first saving the predicted images of a GMM run (K = 8, threshold value = 0.000008) Once this was done,  regionprops were used to find the largest circle in any image that could have a radius of  to describe an area. A grade 4 model could then be fitted from  of the surfaces found to the distances (which are available in the file names of the training images) (MATLAB Polyfit). Finally,  GMM fed the predicted images of the test set into a similar algorithm. As with the previous "training", they were manipulated and circles were found. The area of all these circles was then inserted into the coefficients to estimate a distance
    \begin{itemize}
        \item Distance of Ball Figure 1: 225.7899
        \item Distance of Ball Figure 2: 245.9386
        \item Distance of Ball Figure 3: 222.3892
        \item Distance of Ball Figure 4: 58.3664
        \item Distance of Ball Figure 5: 130.1384
        \item Distance of Ball Figure 6: 191.6834
        \item Distance of Ball Figure 7: 231.1142
        \item Distance of Ball Figure 8: 240.7131

    \end{itemize}

    \includegraphics[scale = 0.6]{polyfitForMeasureDepth.jpg}

    \includegraphics[scale = 0.6]{distance fit.png}

\section{Conclusion}
It is hard to survey the nature of GMM. The outcomes from test pictures 4-8 were discernibly better compared to SG, as the features and shadows were all the more precisely anticipated. For certain pictures, the ball was predominantly perceived and picture 1 was properly without a ball. The calculation actually battled with test pictures 2-3, in any case. We accept that this was to do with the lighting and picture qualitycontrasts in these two pictures. Regardless of whether the shading space or absence of handling to battle this, GMM couldn't perceive the ball with an alternate point. At the day's end, GMM is just K single gaussians. It isn't definitively more safe to these issues, just K-1 additional shadings.
\end{document}

ext: tex


text:
\section{Regular expression syntax}

The lexer is based on the \emph{re}\footnote{\emph{re} is a standard Python module. It handles regular expressions. For further information about \emph{re} you can read \url{http://docs.python.org/lib/module-re.html}} module.
TPG profits from the power of Python regular expressions.
This document assumes the reader is familiar with regular expressions.

You can use the syntax of regular expressions as expected by the \emph{re} module except from the grouping by name syntax since it is used by TPG to decide which token is recognized.

Here is a summary\footnote{From the Python documentation: \url{http://docs.python.org/lib/re-syntax.html}} of the regular expression syntax:

\begin{description}
    \item ["."]
    (Dot.) In the default mode, this matches any character except a newline. If the \emph{DOTALL} flag has been specified, this matches any character including a newline.
    \item ["$\hat{~}$"]
    (Caret.) Matches the start of the string, and in \emph{MULTILINE} mode also matches immediately after each newline.
    \item ["\$"]
    Matches the end of the string or just before the newline at the end of the string, and in \emph{MULTILINE} mode also matches before a newline. $foo$ matches both 'foo' and 'foobar', while the regular expression $foo\$$ matches only 'foo'. More interestingly, searching for $foo.\$$ in 'foo1$\backslash$nfoo2$\backslash$n' matches 'foo2' normally, but 'foo1' in \emph{MULTILINE} mode.
    \item ["*"]
    Causes the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible. $ab*$ will match 'a', 'ab', or 'a' followed by any number of 'b's.
    \item ["+"]
    Causes the resulting RE to match 1 or more repetitions of the preceding RE. $ab+$ will match 'a' followed by any non-zero number of 'b's; it will not match just 'a'.
    \item ["?"]
    Causes the resulting RE to match 0 or 1 repetitions of the preceding RE. $ab?$ will match either 'a' or 'ab'.
    \item [*?, +?, ??]
    The "*", "+", and "?" qualifiers are all greedy; they match as much text as possible. Sometimes this behaviour isn't desired; if the RE $<.*>$ is matched against '$<$H1$>$title$<$/H1$>$', it will match the entire string, and not just '$<$H1$>$'. Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few characters as possible will be matched. Using $.*?$ in the previous expression will match only '$<$H1$>$'.
    \item [$\{$m$\}$]
    Specifies that exactly m copies of the previous RE should be matched; fewer matches cause the entire RE not to match. For example, $a\{6\}$ will match exactly six "a" characters, but not five.
    \item [$\{$m,n$\}$]
    Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as many repetitions as possible. For example, $a\{3,5\}$ will match from 3 to 5 "a" characters. Omitting m specifies a lower bound of zero, and omitting n specifies an infinite upper bound. As an example, $a\{4,\}b$ will match aaaab or a thousand "a" characters followed by a b, but not aaab. The comma may not be omitted or the modifier would be confused with the previously described form.
    \item [\{m,n\}?]
    Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as few repetitions as possible. This is the non-greedy version of the previous qualifier. For example, on the 6-character string 'aaaaaa', $a\{3,5\}$ will match 5 "a" characters, while $a\{3,5\}?$ will only match 3 characters.
    \item ["$\backslash$"]
    Either escapes special characters (permitting you to match characters like "*", "?", and so forth), or signals a special sequence; special sequences are discussed below.
    \item [$\lbrack\rbrack$]
    Used to indicate a set of characters. Characters can be listed individually, or a range of characters can be indicated by giving two characters and separating them by a "-". Special characters are not active inside sets. For example, $[akm\$]$ will match any of the characters "a", "k", "m", or "\$"; $[a-z]$ will match any lowercase letter, and $[a-zA-Z0-9]$ matches any letter or digit. Character classes such as $\backslash$w or $\backslash$S (defined below) are also acceptable inside a range. If you want to include a "$]$" or a "-" inside a set, precede it with a backslash, or place it as the first character. The pattern $[]]$ will match '$]$', for example.

    You can match the characters not within a range by complementing the set. This is indicated by including a "$\hat{~}$" as the first character of the set; "$\hat{~}$" elsewhere will simply match the "$\hat{~}$" character. For example, $[\hat{~}5]$ will match any character except "5", and $[\hat{~}\hat{~}]$ will match any character except "$\hat{~}$".
    \item ["$\vert$"]
    $A|B$, where $A$ and $B$ can be arbitrary REs, creates a regular expression that will match either A or B. An arbitrary number of REs can be separated by the "$\vert$" in this way. This can be used inside groups (see below) as well. As the target string is scanned, REs separated by "$\vert$" are tried from left to right. When one pattern completely matches, that branch is accepted. This means that once A matches, B will not be tested further, even if it would produce a longer overall match. In other words, the "$|$" operator is never greedy. To match a literal "$|$", use $\backslash|$, or enclose it inside a character class, as in $[|]$.
    \item [(...)]
    Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the $\backslash number$ special sequence, described below. To match the literals "(" or ")", use $\backslash($ or $\backslash)$, or enclose them inside a character class: $[(]$ $[)]$.
    \item [(?=...)]
    Matches if ... matches next, but doesn't consume any of the string. This is called a lookahead assertion. For example, $Isaac (?=Asimov)$ will match 'Isaac ' only if it's followed by 'Asimov'.
    \item [(?!...)]
    Matches if ... doesn't match next. This is a negative lookahead assertion. For example, $Isaac (?!Asimov)$ will match 'Isaac ' only if it's not followed by 'Asimov'.
    \item [(?$<$=...)]
    Matches if the current position in the string is preceded by a match for ... that ends at the current position. This is called a positive lookbehind assertion. $(?<=abc)def$ will find a match in "abcdef", since the lookbehind will back up 3 characters and check if the contained pattern matches. The contained pattern must only match strings of some fixed length, meaning that $abc$ or $a|b$ are allowed, but $a*$ and $a\{3,4\}$ are not.
    \item [(?$<$!...)]
    Matches if the current position in the string is not preceded by a match for .... This is called a negative lookbehind assertion. Similar to positive lookbehind assertions, the contained pattern must only match strings of some fixed length. Patterns which start with negative lookbehind assertions may match at the beginning of the string being searched.
    \item [$\backslash A$]
    Matches only at the start of the string.
    \item [$\backslash b$]
    Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of alphanumeric or underscore characters, so the end of a word is indicated by whitespace or a non-alphanumeric, non-underscore character. Note that $\backslash b$ is defined as the boundary between $\backslash w$ and $\backslash W$, so the precise set of characters deemed to be alphanumeric depends on the values of the UNICODE and LOCALE flags. Inside a character range, $\backslash b$ represents the backspace character, for compatibility with Python's string literals.
    \item [$\backslash B$]
    Matches the empty string, but only when it is not at the beginning or end of a word. This is just the opposite of $\backslash b$, so is also subject to the settings of LOCALE and UNICODE.
    \item [$\backslash d$]
    Matches any decimal digit; this is equivalent to the set $[0-9]$.
    \item [$\backslash D$]
    Matches any non-digit character; this is equivalent to the set $[\hat{~}0-9]$.
    \item [$\backslash s$]
    Matches any whitespace character; this is equivalent to the set $[~\backslash t\backslash n\backslash r\backslash f\backslash v]$.
    \item [$\backslash S$]
    Matches any non-whitespace character; this is equivalent to the set $[\hat{~}~\backslash t\backslash n\backslash r\backslash f\backslash v]$.
    \item [$\backslash w$]
    When the LOCALE and UNICODE flags are not specified, matches any alphanumeric character and the underscore; this is equivalent to the set $[a-zA-Z0-9\_]$. With LOCALE, it will match the set $[0-9\_]$ plus whatever characters are defined as alphanumeric for the current locale. If UNICODE is set, this will match the characters $[0-9\_]$ plus whatever is classified as alphanumeric in the Unicode character properties database.
    \item [$\backslash W$]
    When the LOCALE and UNICODE flags are not specified, matches any non-alphanumeric character; this is equivalent to the set $[\hat{~}a-zA-Z0-9\_]$. With LOCALE, it will match any character not in the set $[0-9\_]$, and not defined as alphanumeric for the current locale. If UNICODE is set, this will match anything other than $[0-9\_]$ and characters marked as alphanumeric in the Unicode character properties database.
    \item [$\backslash Z$]
    Matches only at the end of the string.
    \item [$\backslash a ~ \backslash f ~ \backslash n ~ \backslash r ~ \backslash t ~ \backslash v ~ \backslash x ~ \backslash\backslash$]
    Most of the standard escapes supported by Python string literals are also accepted by the regular expression parser.
    \item [$\backslash 0xyz$, $\backslash xyz$] Octal escapes are included in a limited form: If the first digit is a 0, or if there are three octal digits, it is considered an octal escape. As for string literals, octal escapes are always at most three digits in length.
\end{description}

\section{Token definition}                                  \label{lexer:token_def}

\subsection{Predefined tokens}

Tokens can be explicitely defined by the \emph{token} and \emph{separator} keywords.

A token is defined by:

\begin{description}
    \item [a name] which identifies the token.
        This name is used by the parser.
    \item [a regular expression] which describes what to match to recognize the token.
    \item [an action] which can translate the matched text into a Python object. It can be a function of one argument or a non callable object. If it is not callable, it will be returned for each token otherwise it will be applied to the text of the token and the result will be returned. This action is optional. By default the token text is returned.
\end{description}

Token definitions must end with a \emph{;} when no action is specified. The dots after the token name are optional.

See figure~\ref{lexer:tokens} for examples.

\begin{code}
\caption{Token definition examples}                         \label{lexer:tokens}
\begin{verbatimtab}[4]
    #     name     reg. exp        action
    token integer: '\d+'           int;
    token ident  : '[a-zA-Z]\w*'   ;
    token bool   : 'True|False'    $ lambda b: b=='True'

    separator spaces  : '\s+';     # white spaces
    separator comments: '#.*';     # comments
\end{verbatimtab}
\end{code}

The order of the declaration of the tokens is important. The first token that is matched is returned. The regular expression has a special treatment. If it describes a keyword, TPG also looks for a word boundary after the keyword. If you try to match the keywords \emph{if} and \emph{ifxyz} TPG will internally search \verb$if\b$ and \verb$ifxyz\b$. This way, \emph{if} won't match \emph{ifxyz} and won't interfere with general identifiers (\verb$\w+$ for example). This behaviour can be disabled since the version 3 of TPG (see~\ref{grammar:word_boundary_option}).

There are two kinds of tokens. Tokens defined by the \emph{token} keyword are parsed by the parser and tokens defined by the \emph{separator} keyword are considered as separators (white spaces or comments for example) and are wiped out by the lexer.

\subsection{Inline tokens}

Tokens can also be defined on the fly. Their definitions are then inlined in the grammar rules.
This feature may be useful for keywords or punctuation signs.
Inline tokens can not be transformed by an action as predefined tokens.
They always return the token in a string.

See figure~\ref{lexer:inline_tokens} for examples.

\begin{code}
\caption{Inline token definition examples}                  \label{lexer:inline_tokens}
\begin{verbatimtab}[4]
    IfThenElse ->
        'if' Cond
        'then' Statement
        'else' Statement
        ;
\end{verbatimtab}
\end{code}

Inline tokens have a higher precedence than predefined tokens to avoid conflicts (an inlined \emph{if} will not be matched as a predefined \emph{identifier}).

\section{Token matching}                                    \label{lexer:token_matching}

TPG works in two stages.
The lexer first splits the input string into a list of tokens and then the parser parses this list.
The default lexer is lazy in TPG 3. Tokens are generated while parsing.
This way TPG 3 need less memory when parsing huge files.

\subsection{Splitting the input string}

The lexer splits the input string according to the token definitions (see~\ref{lexer:token_def}). When the input string can not be matched a \emph{tpg.LexicalError} exception is raised.

The lexer may loop indefinitely if a token can match an empty string since empty strings are everywhere.

\subsection{Matching tokens in grammar rules}

Tokens are matched as symbols are recognized.
Predefined tokens have the same syntax than non terminal symbols.
The token text (or the result of the function associated to the token) can be saved by the infix \emph{/} operator (see figure~\ref{lexer:token_ret_val}).

\begin{code}
\caption{Token usage examples}                              \label{lexer:token_ret_val}
\begin{verbatimtab}[4]
    S -> ident/i;
\end{verbatimtab}
\end{code}

Inline tokens have a similar syntax. You just write the regular expression (in a string). Its text can also be saved (see figure~\ref{lexer:inline_token_ret_val}).

\begin{code}
\caption{Token usage examples}                              \label{lexer:inline_token_ret_val}
\begin{verbatimtab}[4]
    S -> '\(' '\w+'/i '\)';
\end{verbatimtab}
\end{code}

%\section{Special tokens}                                    \label{lexer:special_tokens}
%
%Their are some special tokens that have been requested by some users but these tokens can not be easily
%described by TPG using classical token definition (see~\ref{lexer:token_def}).
%
%\subsection{Indent and deindent tokens}                     \label{lexer:indent_deindent}
%
%TPG is written in Python so is should be easy to handle INDENT and DEDENT tokens as in Python language.
%These tokens are introduced in the source to be parsed by a preprocessor, before the lexer is activated.
%Spaces in the beginning the lines are replaced by indent and deindent tokens when needed.
%These special tokens are characters which ASCII codes are 16 and 17.
%These characters may not be used in regular text files.
%
%\subsubsection{Indent definition}
%
%The \emph{indent} option (see~\ref{grammar:options}) has been added to define the indentation.
%It has two values.
%The first one is a regular expression describing the indentation, usually spaces and tabulations.
%The second one is a regular expression describing the lines not to be taken into account, usually comments.
%This second parameter describes the beginning of the line, i.e. \emph{"\#"} will match lines starting
%with a \emph{\#}.
%
%\begin{code}
%\caption{Indent and deindent definition example}            \label{lexer:indent_definition}
%\begin{verbatimtab}[4]
%    set indent = "\s", "#"
%\end{verbatimtab}
%\end{code}
%
%\subsubsection{Indent and deindent usage}                   \label{lexer:indent_usage}
%
%When the \emph{indent} option is active, \emph{indent} and \emph{deindent} tokens are defined.
%They can be used as any other token.
%
%\begin{code}
%\caption{Indent and deindent example}            \label{lexer:indent_example}
%\begin{verbatimtab}[4]
%parser IndentParser:
%
%    set indent = "\s", "#"
%
%    BLOCK ->
%        (   INSTR
%        |   indent
%                BLOCK
%            deindent
%        )*;
%\end{verbatimtab}
%\end{code}


text:
\documentclass[margin,line]{res}

\oddsidemargin -.5in
\evensidemargin -.5in
\textwidth=6.0in
\itemsep=0in
\parsep=0in

\newenvironment{list1}{
  \begin{list}{\ding{113}}{%
      \setlength{\itemsep}{0in}
      \setlength{\parsep}{0in} \setlength{\parskip}{0in}
      \setlength{\topsep}{0in} \setlength{\partopsep}{0in}
      \setlength{\leftmargin}{0.17in}}}{\end{list}}
\newenvironment{list2}{
  \begin{list}{$\bullet$}{%
      \setlength{\itemsep}{0in}
      \setlength{\parsep}{0in} \setlength{\parskip}{0in}
      \setlength{\topsep}{0in} \setlength{\partopsep}{0in}
      \setlength{\leftmargin}{0.2in}}}{\end{list}}

\usepackage{color}
\usepackage{amsfonts}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=blue,
}
\urlstyle{same}

\begin{document}

\name{Sanghyun Kim \vspace*{.1in}}

\begin{resume}

\section{\sc Current Affiliation}

\textbf{Senior Researcher}, Dept. of AI Machinery, \\
System Engineering Research Division, \\
Korea Institute of Machinery \& Materials (KIMM)
%\\
%\textbf{Visiting Researcher} (until 2019.6) at the Gepetto Team,\\
%Laboratory for Analysis and Architecture of Systems (LAAS), \\
%Centre National de la Recherche Scientifique (CNRS)

%Research Associate at Stanford Artificial Intelligence Laboratory\\
%Computer Science Department, Stanford University

\section{\sc Contact Information}
%\vspace{.05in}
%\begin{tabular}{@{}p{2in}p{4in}}
%Gates 122             & {\it Phone:}  (650) 796-9566 \\
%Stanford University & {\it E-mail:}  park73@ai.stanford.edu\\
%Stanford, CA  94305 USA  & {\it WWW:} ai.stanford.edu/\verb+~+park73 \\
%\end{tabular}
{\it Address:} 105/7 Causewayside, Edinburgh, United Kingdomg\\
{\it E-mail:}  sanghyun.kim@ed.ac.uk\\
{\it Phone:}  +44-07305-403313\\
{\it WWW:}  \url{http://ggory15.github.io} \textit{(for my projects)}, \url{http://github.com/ggory15} \textit{(for source codes)}

%%\section{\sc Objective}
%%Seeking a research position in the area of modeling/analysis, or AI/control for
%%complex dynamical systems.

\section{\sc Education}

{\bf Seoul National University}, Seoul, Korea  \hfill {\bf 2012.3 - 2020.2} \\
\vspace*{-.1in}
\begin{list1}
\vspace*{-.05in}
\item[] Ph.D.  of Dept of Trandisciplinary Studies
\begin{list2}
%\vspace*{.05in}
\item Lab: Dynamic Robotic System Lab (DYROS Lab, \url{https://dyros.snu.ac.kr})
\item Advisor: Professor Jaeheung Park (park73@snu.ac.kr)
\end{list2}
\end{list1}

{\bf Seoul National University}, Seoul, Korea  \hfill {\bf 2005.3 - 2012.2} \\
%{\em Department of Aeronautics and Astronautics}
\vspace*{-.1in}
\begin{list1}
\vspace*{-.05in}
\item[] B.A., Mechanical Engineering,  March, 2012
\end{list1}

\section{\sc Research \\Experience}

{\bf University of Edinburgh}, United Kingdom  \hfill {\bf 2020.4 - 2020.9} \\
\vspace*{-.1in}
\begin{list1}
\vspace*{-.05in}
\item[] Research Associate (Post-doctoral Researcher)
\begin{list2}
\item Lab:  Statistical Machine Learning and Motor Control Group (\url{http://web.inf.ed.ac.uk/slmc})
\item Advisor: Prof. Sethu Vijayakumar (sethu.vijayakumar@ed.ac.uk)
\end{list2}
\end{list1}

{\bf Centre National de la Recherche Scientifique (CNRS)}, France  \hfill {\bf 2018.8 - 2019.6} \\
\vspace*{-.1in}
\begin{list1}
\vspace*{-.05in}
\item[] Visiting Researcher
\begin{list2}
\item Lab: Gepetto Team (\url{http://projects.laas.fr/gepetto})
\item Advisor: Dr. Nicolas Mansard (nmansard@laas.fr)
\item Funding: Korean government grant
\end{list2}
\end{list1}

{\bf Gwangju Institute of Science and Technology (GIST)}, Korea  \hfill {\bf 2010.6  - 2010.9} \\
\vspace*{-.1in}
\begin{list1}
\vspace*{-.05in}
\item[] Student Internship
\begin{list2}
\item Lab: Haptic Team (\url{http://dyconlab.gist.ac.kr})
\item Advisor: Prof. Jeha Ryu (ryu@gist.ac.kr)
\end{list2}
\end{list1}

\section{\sc Research\\ Interests}
\textbf{Hierarchical whole-body control} of bipedal robot and mobile-based humanoid \\
\textbf{Task and contact transition algorithm} for hierarchical controller \\
\textbf{Torque-based task space control} \\
\textbf{Whole-body planning} for high redundant robot \\
\textbf{Dexterous robot hand control} \\
\textbf{Manipulation of redundant robotic system}

\section{\sc Research\\ Experience}
{\bf During visiting researcher in Gepetto Team, LAAS-CNRS, France}

\vspace{-.3cm}
\textbf{\emph {Whole-body Planning for Humanoid}} \hfill {\bf 2018 - Presence}
\begin{list2}
\item (Ongoing Work) Generating contact sequence, CoM trajectory, feet trajectories, and whole-body trajectory for legged robots.
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Video: \url{https://youtu.be/JpwigzMQg6E}
\vspace*{-.05in}
\end{itemize}
\item Implementation of CoM trajectory generator based on \textit{Time Optimization}.
\item Implementation of feet trajectories using the concept of hyper-plane.
\item Implementation of Quadratic Programming (QP)-based whole-body planner in C++ and Python:
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Video: \url{https://youtu.be/nHiLV89cMG8}
\vspace*{-.05in}
\item[\checkmark] Codes: \url{https://github.com/ggory15/tsid_python_binding}
\vspace*{-.05in}
\end{itemize}
\end{list2}

\textbf{\emph { Model Predictive Control for Humanoid}} \hfill {\bf 2018 - Presence}
\begin{list2}
\item (Ongoing Work) Developing whole-body controller using Differential Dynamic Programming (DDP).
\item (Ongoing Work) Implementation of DDP-based controller with the collision avoidance constraint.
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] (Preliminary) Video : \url{https://youtu.be/rq3dXdt8t0E}
\vspace*{-.05in}
\end{itemize}
\end{list2}

{\bf During Ph.D. student}

\vspace{-.3cm}

\textbf{\emph { Multiple Task Execution Algorithm}} \hfill  {\bf 2017  - 2020}
\begin{list2}
\item Dynamic task transition algorithm to generate complex behavior.
\item Continuous transitions between arbitrary tasks using the activation parameter [J5].
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Insertion and removal both equality and inequality tasks without discontinuity of the control input.
\vspace*{-.05in}
\item[\checkmark] Development of avoidance tasks including joint-limit, singularity, and obstacle.
\vspace*{-.05in}
\item[\checkmark] Video : \url{https://youtu.be/-lfnLhmSk3M}
\vspace*{-.05in}
\item[\checkmark] Codes: \url{https://ggory15.github.io/tasktransition-project}
\vspace*{-.05in}
\end{itemize}
\item (Ongoing Work) Applying the task transition method to operate mobile-based humanoid
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Development controller for archiving complex tasks [C8]
\vspace*{-.05in}
\item[\checkmark] Self-collision avoidance algorithm using the concept of attractive force [O1]
\vspace*{-.05in}
\item[\checkmark] Video : \url{https://youtu.be/K8RnMAA0rg4}
\vspace*{-.05in}
\end{itemize}
\item (Ongoing Work) Multi-contact transition for humanoids using Gravito-Inertial Wrench Cone (GIWC)
\end{list2}

\textbf{\emph { Whole-body Control of Torque-controlled Humanoids}} \hfill {\bf 2014 - Presence}
\begin{list2}
\item Design and development of torque-controlled humanoid, DYROS-Red [C2].
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] EtherCAT and RTX programming for real-time control
\vspace*{-.05in}
\item[\checkmark] High-level controller: Whole-body controller
\vspace*{-.05in}
\item[\checkmark] Low-level controller: Elmo motion controller
\vspace*{-.05in}
\item[\checkmark] Video : \url{https://youtu.be/01E-rKixNfE}
\vspace*{-.05in}
\end{itemize}
\item Implementation of whole-body controllers for torque-controlled humanoids.
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Using operational-space controller [C2]
\vspace*{-.05in}
\item[\checkmark] Using hierarchical QP-based controller [J4, J6]
\vspace*{-.05in}
\item[\checkmark] Using DDP-based controller
\vspace*{-.05in}
\end{itemize}
\item (Ongoing Work) Development contact force generator with multi-constraints for dynamic balance.
\end{list2}

\textbf{\emph { Control of Position-controlled Humanoids}} \hfill {\bf 2014  - 2018}
\begin{list2}
\item Design and development of position-controlled humanoid, DYROS-Jet [J2, J4].
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] RS-232 communication with 200 Hz
\vspace*{-.05in}
\item[\checkmark] High-level controller: Jacobian-based controller
\vspace*{-.05in}
\item[\checkmark] Low-level controller: Robotis controller
\vspace*{-.05in}
\item[\checkmark] Video : \url{https://youtu.be/9UwJQREUjtc}
\vspace*{-.05in}
\end{itemize}
\item Implementation of inverse kinematics controllers for position-controlled humanoids
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] using Jacobian-based inverse kinematics controller [J2, J4, C3, W2]
\vspace*{-.05in}
\item[\checkmark] using Forward And Backward Reaching Inverse Kinematics (FABRIK) [C7]
\vspace*{-.05in}
\item[\checkmark] using Recursive Neural Network (RNN) [C5]
\vspace*{-.05in}
\end{itemize}
\item Disturbance observer to enhance balancing performance [C6]
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Feed-forward joint disturbance observer for compliant motion
\vspace*{-.05in}
\item[\checkmark] Video:  \url{https://youtu.be/LHGxx0M9ijs}
\vspace*{-.05in}
\end{itemize}
\end{list2}

\textbf{\emph {Singularity avoidance algorithm}} \hfill {\bf 2016  - 2017}
\begin{list2}
\item Comparative analysis of six representative singularity avoidance algorithms:
\\ Damped Pseudo Inverse, Error Damped Pseudo Inverse, Jacobian Transpose, Selectively Damped Inverse, Filtered Inverse, and Task Transition Method
\end{list2}

\textbf{\emph { Development of humanoid system for DRC Finals 2015}} \hfill {\bf 2014  - 2016}
\begin{list2}
\item {Student leader} of Team SNU
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Managing the whole framework of robot
\vspace*{-.05in}
\item[\checkmark] Developing the upper-body and lower-body position controller
\vspace*{-.05in}
\end{itemize}
\item No falling down during the competitions and 12th in DRC Finals 2015 [J2, J4, C3, W2]
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Video: \url{https://youtu.be/aWpyfKkbzf0}
\vspace*{-.05in}
\end{itemize}
\end{list2}

\textbf{\emph { Artificial intelligence robot CPR system}} \hfill {\bf 2014  - 2016}
\begin{list2}
\item Robot manipulator to perform CPR in emergency situations [P2, J3]
\item Automatic System based biological data from a patient
\item Simulation on mannequin and animal test
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Video: \url{https://youtu.be/D9saZERvzf8}
\vspace*{-.05in}
\end{itemize}
\end{list2}

\textbf{\emph { Robot hand tele-operation control}} \hfill {\bf 2012  - 2014}
\begin{list2}
\item Robot hand synergy mapping using multi-factor model [P1, J1, W1]
\item Extracting synergy by considering individual characteristic as well as grasping motion
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Video: \url{https://youtu.be/QzGgV9KHaZI}
\vspace*{-.05in}
\end{itemize}
\item Grasping Force Estimation using sEMG signals [J5]
\end{list2}

\textbf{\emph { Tele-opeartion control of ultrasonic examination system}} \hfill {\bf 2012  - 2013}
\begin{list2}
\item Tele-operated robotic arm for remote ultra-sound exam
\item Automated orientation control for ultrasound
\item Contact force feedback using haptic device
\begin{itemize}
\vspace*{-.05in}
\item[\checkmark] Video: \url{https://youtu.be/_OSkL5e70fI}
\vspace*{-.05in}
\end{itemize}
\end{list2}

{\bf During internship in GIST, Korea}

\vspace{-.3cm}
\textbf{\emph { Friction and Gravity Compensator for Surgery Simulator }} \hfill {\bf 2010.6  - 2010.9}
\begin{list2}
\item Research and development on the Laparoscopic simulator
\item Haptic Feedback using friction and gravity compensator [C1]
\end{list2}

\section{\sc Technical skills}
{\bf Hardware  Experience} \\
\textbf{\emph { Human-sized Humanoids}}
\begin{list2}
\item Torque controlled robot, \textit{DYROS-Red}
\item Position controlled robot, \textit{DYROS-Jet}
\item Torque controlled robot, \textit{TALOS (PAL Robotics Co.)}
\item Position controlled robot, \textit{HRP-2}
\end{list2}
\vspace{-0.3cm}

\textbf{\emph { Mobile-based Humanoids}}
\begin{list2}
\item Four-wheeled mobile base, \textit{Husky}, with 7-DoF arm, \textit{Franka Panda}
\end{list2}
\vspace{-0.3cm}

\textbf{\emph { Manipulator}}
\begin{list2}
\item 7-DoF arm, \textit{Franka Panda}
\item 6-DoF arm, \textit{Roman-3D}
\item 6-DoF arm, \textit{Denso Arm}
\end{list2}
{\bf Software Experience} \\
\textbf{\emph { Programming Skills}}
\begin{list2}
\item Intermediate C++, Python, and Matlab programming for robotics (Windows, Ubuntu 18.04)
\item V-Rep, MuJoCo, Gazebo, and PyBullet for robotic simulation
\end{list2}
\vspace{-0.3cm}
\textbf{\emph { Libraries}}
\begin{list2}
\item Math - Eigen, Lapack, MKL
\item Optimization - qpOASES, Eiquadprog, IFOPT and IPOPT
\item Robot Kinematics and Dynamics: Pinocchio, RBDL
\item Others: Boost (in particular, boost-python), FCL
\end{list2}

\section{\sc Honors and Awards}
\textbf{Best thesis award} from Seoul National University, 2020.\\
\textbf{Best conference paper award} in IEEE/ASME International Conference on Advanced Robotics and Mechatronics, 2019.\\
\textbf{Korean government grant} for Visiting Scholar of LAAS-CNRS, 2018. \\
\textbf{Best paper award} in Journal of Korea Robotics Society (JKROS), 2018.\\
\textbf{Cum laude} from Dept. of Mechanical Engineering at Seoul National University, 2012.

\section{\sc Patents}
[P2]  \textbf{Sanghyun Kim} \textit{et al}. Automatic cardiopulmonary resuscitation device and control method therefor, US Patent, No. 20190029919A1, CN Patent, No. 108697572A, EU Patent, No. 3409258A1, 2019

[P1] \textbf{Sanghyun Kim}, {Jaeheung Park}, Mingon Kim, Jimin Lee, Jounghuem Kwon, Bumjae You.
APPARATUS FOR ESTIMATING GRASPING POSTURE AND GRASPING FORCE.
Korea Patent, No.10-2016-0075150, 2016.

%\vspace*{-2.5mm}
%NSF Vertical Integration of Research and Education in Statistics and
%Mathematical Sciences\\ (VIGRE) teaching fellowship.
%

\section{\sc International Journal Articles}
[J6] S. Hong, K. Jang, \textbf{S. Kim}, and J. Park.
Regularized Hierarchical Quadratic Program for Real-Time Whole-Body Motion Generation ,
IEEE/ASME Transactions on Mechatronics, 2020. 10 (Early Access)

[J5] \textbf{S. Kim}, M. Kim, J. Kim, S, Kim, and J. Park.
Grasping Force Prediction by EMG Signals and Arm Posture: Tensor Decomposition Based Approach,
Journal of Bionic Engineering, Vol. 16, No. 3, pp.  455-467, 2019.05

[J4] \textbf{S. Kim}, K. Jang, S. Park, Y. Lee, S. Y. Lee, and J. Park, Continuous Task Transition Approach for Robot Controller based on Hierarchical Quadratic Programming, IEEE Robotics and Automation Letters (with International Conference on Robotics and Automation 2019), Vol. 4, No. 2, pp. 1603-1610, 2019.05

[J3] \textbf{S. Kim}, M. Kim, J. Lee, S. Hwang, J. Chae, B. Park, H. Cho, J. Sim, J. Jung, H. Lee, S. Shin, M. Kim, W. Choi, Y. Lee, S. Park, J. Oh, Y. Lee, S. Lee, M. Lee, S. Yi, K. Chang, N. Kwak, and {J. Park}.
Team SNU’s Control Strategies to Enhancing Robot’s Capability: Lessons from the DARPA Robotics Challenge Finals 2015, The DARPA Robotics Challenge Finals: Humanoid Robots to the Rescue, Springer, pp. 347-379, 2018.04

[J2] \textbf{S. Kim}, M. Kim, J. Lee, S. Hwang, J. Chae, B. Park, H. Cho, J. Sim, J. Jung, H. Lee, S. Shin, M. Kim, W. Choi, Y. Lee, S. Park, J. Oh, Y. Lee, S. Lee, M. Lee, S. Yi, K. Chang, N. Kwak, and {J. Park}.
Team SNU’s Control Strategies to Enhancing Robot’s Capability: Lessons from the 2015 DARPA Robotics Challenge Finals. Journal of Field Robotics, Vol. 34, No. 2, pp. 359-380, 2017.03

[J1] \textbf{S. Kim}, M. Kim, J. Lee, and {J. Park}.
Robot Hand Synergy Mapping Using Multi-factor Model and EMG signal.
(with International Symposium on Experimental Robotics 2014), Springer, pp.671-683, 2015.11

\section{\sc International Conference Articles}
[C8] \textbf{S. Kim}, K. Jang, S. Park, Y. Lee, S. Y. Lee, and J. Park, Whole-body Control of Non-holonomic Mobile Manipulator Based on Hierarchical Quadratic Programming and Continuous Task Transition. IEEE International Conference on Advanced Robotics and Mechatronics (ARM), Osaka, Japan, 2019, \textbf{Best Conference Paper Award}

[C7] \textbf{S. Kim}, J. Kim, and J. Park.
Real-time Inverse Kinematics Technique for Controlling Humanoid Avatar with Redundant Arm,
Ubiquitous Robot 2018, Hawaii, USA, 2018.

[C6] M. Kim, J. Kim, \textbf{S. Kim}, J. Sim, and J. Park.
Disturbance Observer based Linear Feedback Controller for Compliant Motion of Humanoid Robot,
International Conference on Robotics and Automation (ICRA), Australia, 2018.

[C5] M. Kim, \textbf{S. Kim}, and {J. Park}.
Human Motion Imitation for Humanoid by Recurrent Neural Network.
The 13th International Conference on Ubiquitous Robots and Ambient Intelligence,
Xian, China, 19-22 Aug, 2017.

[C4] J. Jung, J. Kim, \textbf{S. Kim}, W. Kwon, S. Na, K. Kim, J. Lee, G. Suh, and J. Park.
Application of Robot Manipulator for Cardiopulmonary Resuscitation,  International Symposium on Experimental Robotics 2016, Springer, pp. 266-274, 2017.03

[C3] \textbf{S. Kim}, M. Kim, J. Lee, S. Hwang, J. Chae, B. Park, H. Cho, J. Sim, J. Jung, H. Lee, S. Shin, M. Kim, N. Kwak, Y. Lee, S. Lee, M. Lee, S. Yi, K. K.C. Chang, and {J. Park}.
Approach of Team SNU to the DARPA Robotics Challenge Finals.
2015 IEEE-RAS International Conference on Humanoid Robots,
Seoul, Korea, 3-5 Nov 2015.

[C2] M. Schwartz, S. Hwang, Y. Lee, J. Won, \textbf{S. Kim}, and {J. Park}.
Aesthetic Design and Development of Humanoid Legged Robot.
The 2014 IEEE-RAS International Conference on Humanoid Robots,
Madrid, Spain, 18-20 Nov 2014.

[C1] \textbf{S. Kim}, C. Lee, and J. Ryu.
Data-driven Haptic Rendering of Friction between Surgical Device and Trocar for Laparoscopic Surgery Simulator,
ACCAS 2010, Busan, Korea, 2010.

\section{\sc Domestic \\ Journal Articles}

[DJ6] K. Jang, \textbf{S. Kim}, S. Park, and J. Park.
Unified Framework for Overcoming Motion Constraints of Robots Using Task Transition Algorithm,
Journal of Korea Robotics Society, Vol. 13, No. 2, 2018.

[DJ5] J. Kim, \textbf{S. Kim}, and {J. Park}.
The Trends of HRI: Focusing on Task Oriented Robot User Interface,
Robot and Human,
Vol. 14, No. 4, 2017.

[DJ4] \textbf{S. Kim} and {J. Park}.
Singularity Avoidance Algorithms for Controlling Robot Manipulator: A Comparative Study,
Journal of Korea Robotics Society, Vol. 12, No. 1, 2017. \textbf{Best Paper Award}

[DJ3] S. Shin, M. Kim, J. Ahn, \textbf{S. Kim}, and J. Park.
Development of Tele-operation Interface and Stable Navigation Strategy for Humanoid Robot Driving,
Journal of Institute of Control, Robotics and Systems, Vol. 22, No. 11, 2016.

[DJ2] \textbf{S. Kim}, B. Park, and {J. Park}.
DRC Finals 2015 – Analysis of Participants,
Robot and Human,
Vol. 12, No. 4, 2015.

[DJ1] \textbf{S. Kim}, C. Lee, J. Kim, and J. Ryu.
Approximate Friction and Gravity Compensation in Haptic Laparoscopic Surgery Simulator,
Transactions of the KSME,
Vol. 35, No. 8, 2010.

\section{\sc Domestic Conference Articles}
[DC9] S. Park, K. Jang, S. Kim, \textbf{S. Kim}, and J. Park.
nverse Kinematics Minimizing JointsTorque with Given Target Wrench,
The 15th Korea Robotics Society Annual Conference (KROC), Korea, 2020.

[DC8] S. Y. Lee, S. Park, K. Jang, \textbf{S. Kim}, S. Kim, and J. Park.
A Comparative Study of Tracking Control with Closed Loop Inverse Kinematics Algorithm,
The 14th Korea Robotics Society Annual Conference (KROC), Korea, 2019.

[DC7] J. Jang, \textbf{S. Kim}, S. Park, S. Y. Lee, and J. Park
Self-collision Avoidance Algorithm for Robot Manipulator using Continuous Task Transition Algorithm,
The 14th Korea Robotics Society Annual Conference (KROC), Korea, 2019.

[DC6] K. Jang, \textbf{S. Kim}, S. Park, and J. Park,
Joint Limit Avoidance of Non-holonomic Mobile Manipulator using Weighting Matrix in Generalized Pseudo-Inverse, Conference on Korean Society for Precision Engineering, Korea, 2017.

[DC5] M. Kim, R. Destenay, \textbf{S. Kim}, J. Kwon, K. Yeom, {J. Park}, and B. You.
Avatar Motion Generation by Null-Space Mapping Based on Minimum Number of Markers.
2015 Conference on Information and Control Systems,
Sokcho, Korea, 2015.

[DC4] \textbf{S. Kim}, M. Kim, and J. Park.
Extracting Postural Synergies Using Grasping Taxonomy,
The 9th Korea Robotics Society Annual Conference (KROC), Korea, 2014.

[DC3] J. Lee, M. Kim, \textbf{S. Kim}, and J. Park.
Estimation of Hand Posture and Grasping Force Using Surface EMG,
The 9th Korea Robotics Society Annual Conference (KROC), Korea, 2014.

[DC2] \textbf{S. Kim}, C. Lee, J. Kim, and J. Ryu.
Friction and Gravity Compensation in Haptic Laparoscopic Surgery Simulator,
Conference on Korean Society of Mechanical Engineers (KSME), Korea, 2010.

[DC1] \textbf{S. Kim}, C. Lee, J. Kim, and J. Ryu.
Trocar Friction modelling for Friction and gravity Compensation,
Conference on Korean Society of Mechanical Engineers (KSME), Korea, 2010.

\section{\sc Workshops}
[W2] \textbf{S. Kim} and {J. Park}.
Control Strategies of Team SNU for DRC Finals, and Future Directions for Robots in Human Environment.
Invited speaker at Workshop on “What did we do for the DARPA Robotics Challenge?,
2015 IEEE-RAS International Conference on Humanoid Robots,
Seoul, Korea, 3-5 Nov 2015.

[W1] \textbf{S. Kim}, J. Lee, M. Kim, and {J. Park}.
Teleoperated Robot Hand Control using Tensor Decomposition.
Full-day Tutorial on Robotics-based Methods for the Identification, Recognition, and Synthesis of Human Motions,
IEEE/RSJ International Conference on Intelligent Robots and Systems,
Tokyo, Japan, 3 Nov 2013.

\section{\sc Ongoing Papers}

[O1] Y. Lee, \textbf{S. Kim},  J. Park, N. Tsagarakis, and J. Lee, EOS-WBC: Enhanced Operational-space Based Whole Body Control Framework under Inequality Constraints, Roboics and Autonomous Systems, under review, 2020.

[O2] S. Hong, K. Jang,  \textbf{S. Kim},  J. Park, Regularized Hierarchical Quadratic Program for Real-Time Whole Body Motion Generation, Transaction on Mechatronics, minor revision, 2020.

\section{\sc Academic \\Services}

Reviewer for IEEE Robotics and Automation Letters (RAL), 2015. \\
Reviewer for IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2018. \\
Reviewer for IEEE International Conference on Ubiquitous Robots (UR), 2018.\\
Reviewer for IEEE International Conference on Robotics and Automation (ICRA), 2019. \\
Reviewer for IEEE Robotics and Automation Letters (RAL), 2019. \\
Reviewer for IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2020. \\
\end{resume}
\end{document}

\grid
\grid
\grid