Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
pdbparser
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NOEL Philippe
pdbparser
Commits
09450558
Commit
09450558
authored
Nov 30, 2018
by
NOEL Philippe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add doc in atom
parent
98da9fc3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
20 deletions
+43
-20
src/main.rs
src/main.rs
+2
-2
src/pdb/atom.rs
src/pdb/atom.rs
+8
-5
src/pdb/protein.rs
src/pdb/protein.rs
+1
-1
src/pdb/read_pdb.rs
src/pdb/read_pdb.rs
+9
-8
src/pdb/residue.rs
src/pdb/residue.rs
+7
-0
tests/test.rs
tests/test.rs
+16
-4
No files found.
src/main.rs
View file @
09450558
...
...
@@ -8,7 +8,7 @@ fn main() {
println!
(
"Prot : {}
\n
n chain: {}
\n
n res: {}
\n
n atom: {}"
,
my_prot
.name
,
my_prot
.get_number_chain
(),
my_prot
.get_number_residue
(),
my_prot
.get_number_atom
());
println!
(
"Reduce protein"
);
let
chain
A
=
my_prot
.select_atoms
(
"chain a"
)
.unwrap
();
println!
(
"Prot : {}
\n
n chain: {}
\n
n res: {}
\n
n atom: {}"
,
chain
A
.name
,
chainA
.get_number_chain
(),
chainA
.get_number_residue
(),
chainA
.get_number_atom
());
let
chain
_a
=
my_prot
.select_atoms
(
"chain a"
)
.unwrap
();
println!
(
"Prot : {}
\n
n chain: {}
\n
n res: {}
\n
n atom: {}"
,
chain
_a
.name
,
chain_a
.get_number_chain
(),
chainA
.get_number_residue
(),
chainA
.get_number_atom
());
}
src/pdb/atom.rs
View file @
09450558
...
...
@@ -17,6 +17,7 @@ pub struct Atom {
impl
Atom
{
/// Create a new structure Atom. An atom have a name, a number and x, y, z coordinates
/// If the atom name is "C", "CA", "N", "O", "OT1" or "OT2", it will be consider as backbone
///
/// # Examples
///
...
...
@@ -28,11 +29,7 @@ impl Atom {
/// ````
pub
fn
new
(
name
:
String
,
number
:
u64
,
coord
:
[
f32
;
3
])
->
Atom
{
let
n
=
name
.deref
();
let
back
=
if
n
==
"C"
||
n
==
"CA"
||
n
==
"N"
||
n
==
"O"
||
n
==
"OT1"
||
n
==
"OT2"
{
true
}
else
{
false
};
let
back
=
n
==
"C"
||
n
==
"CA"
||
n
==
"N"
||
n
==
"O"
||
n
==
"OT1"
||
n
==
"OT2"
;
Atom
{
name
,
number
,
...
...
@@ -41,6 +38,12 @@ impl Atom {
}
}
/// Get the name of the atom
///
pub
fn
name
(
self
)
->
String
{
self
.name
.clone
()
}
/// Compute the distance between 2 Atoms
///
/// # Examples
...
...
src/pdb/protein.rs
View file @
09450558
...
...
@@ -286,7 +286,7 @@ impl<'a> Protein {
// ex: don't parse the chain if it's not selected
pub
fn
select_atoms
(
&
self
,
pattern
:
&
str
)
->
Option
<
Protein
>
{
let
mut
n_prot
=
Protein
::
new
(
String
::
from
(
self
.name
.clone
()
));
let
mut
n_prot
=
Protein
::
new
(
self
.name
.clone
(
));
let
select
=
match
selection_atom
::
parse_select
(
&
pattern
)
{
Some
(
x
)
=>
x
,
...
...
src/pdb/read_pdb.rs
View file @
09450558
...
...
@@ -12,7 +12,7 @@ use super::protein::Protein;
/// # Errors
/// Will return 0.0 if the String cannot be convert and print the error
///
fn
parse_float
(
s
:
&
String
)
->
f32
{
fn
parse_float
(
s
:
&
str
)
->
f32
{
match
s
.trim
()
.parse
::
<
f32
>
()
{
Ok
(
n
)
=>
n
,
Err
(
e
)
=>
{
...
...
@@ -30,15 +30,15 @@ fn parse_float(s: &String) -> f32 {
/// # Errors
/// Will return 0 if the String cannot be convert and print the error
///
fn
parse_int
(
s
:
&
String
)
->
i64
{
fn
parse_int
(
s
:
&
str
)
->
i64
{
match
s
.trim
()
.parse
::
<
i64
>
()
{
Ok
(
n
)
=>
n
,
Err
(
e
)
=>
{
match
i64
::
from_str_radix
(
s
.trim
(),
16
)
{
Ok
(
n
)
=>
return
n
,
Ok
(
n
)
=>
n
,
Err
(
_
)
=>
{
println!
(
"{}"
,
e
);
return
0
0
}
}
}
...
...
@@ -79,7 +79,7 @@ pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
let
l
=
line
.unwrap
();
if
l
.starts_with
(
"HETAM"
)
||
l
.starts_with
(
"ATOM"
)
{
let
atom_name
=
&
l
[
12
..
17
]
.trim
()
.to_string
();
let
residue_name
=
&
l
[
17
..
20
]
.trim
()
.to_string
()
;
let
residue_name
=
&
l
[
17
..
20
]
.trim
();
let
chain
=
l
[
21
..
22
]
.chars
()
.next
()
.unwrap
();
let
atom_number
=
parse_int
(
&
l
[
6
..
11
]
.to_string
());
let
residue_number
=
parse_int
(
&
l
[
22
..
26
]
.to_string
());
...
...
@@ -87,14 +87,15 @@ pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
let
y
=
parse_float
(
&
l
[
38
..
46
]
.to_string
());
let
z
=
parse_float
(
&
l
[
46
..
54
]
.to_string
());
if
is_protein_res
(
residue_name
,
&
lst_res
)
{
protein
.update_protein
(
chain
,
residue_name
.
clone
(),
residue_number
as
u64
,
atom_name
.clone
(),
atom_number
as
u64
,
[
x
,
y
,
z
]);
protein
.update_protein
(
chain
,
residue_name
.
to_string
(),
residue_number
as
u64
,
atom_name
.clone
(),
atom_number
as
u64
,
[
x
,
y
,
z
]);
}
}
}
protein
}
fn
is_protein_res
(
r
:
&
str
,
lst
:
&
Vec
<&
str
>
)
->
bool
{
/// Test if the selected line is a residue
///
fn
is_protein_res
(
r
:
&
str
,
lst
:
&
[
&
str
])
->
bool
{
let
r
=
r
.to_uppercase
();
...
...
src/pdb/residue.rs
View file @
09450558
...
...
@@ -34,7 +34,14 @@ impl Residue {
}
}
/// Get the name of the residue
///
pub
fn
name
(
&
self
)
->
String
{
self
.name
.clone
()
}
/// Get the number of the residue
///
pub
fn
get_res_num
(
&
self
)
->
u64
{
self
.res_num
}
...
...
tests/test.rs
View file @
09450558
...
...
@@ -2,8 +2,8 @@ extern crate pdbparser;
#[test]
fn
parse_f2
()
{
use
pdbparser
;
let
my_prot
=
pdbparser
::
parse_pdb
(
"tests/tests_file/f2.pdb"
,
"f2"
);
assert_eq!
(
"f2"
,
my_prot
.name
());
assert_eq!
(
1
,
my_prot
.get_number_chain
());
assert_eq!
(
66
,
my_prot
.get_number_residue
());
assert_eq!
(
1085
,
my_prot
.get_number_atom
());
...
...
@@ -11,7 +11,6 @@ fn parse_f2() {
#[test]
fn
parse_f2_adn
()
{
use
pdbparser
;
let
my_prot
=
pdbparser
::
parse_pdb
(
"tests/tests_file/f2_adn.pdb"
,
"f2"
);
assert_eq!
(
1
,
my_prot
.get_number_chain
());
assert_eq!
(
66
,
my_prot
.get_number_residue
());
...
...
@@ -20,7 +19,6 @@ fn parse_f2_adn() {
#[test]
fn
parse_trp
()
{
use
pdbparser
;
let
my_prot
=
pdbparser
::
parse_pdb
(
"tests/tests_file/trp_MD.pdb"
,
"trp"
);
assert_eq!
(
1
,
my_prot
.get_number_chain
());
assert_eq!
(
704
,
my_prot
.get_number_residue
());
...
...
@@ -29,9 +27,23 @@ fn parse_trp() {
#[test]
fn
parse_5jpq
()
{
use
pdbparser
;
let
my_prot
=
pdbparser
::
parse_pdb
(
"tests/tests_file/5jpq.pdb"
,
"5jpq"
);
assert_eq!
(
35
,
my_prot
.get_number_chain
());
assert_eq!
(
8173
,
my_prot
.get_number_residue
());
assert_eq!
(
44801
,
my_prot
.get_number_atom
());
}
#[test]
fn
f2_res
()
{
let
mut
my_prot
=
pdbparser
::
parse_pdb
(
"tests/tests_file/f2.pdb"
,
"f2"
);
let
chain_a
=
my_prot
.get_chain_ref
(
'A'
)
.unwrap
();
let
res
=
chain_A
.get_residue_ref
(
1
)
.unwrap
();
assert_eq!
(
"THR"
,
res
.name
());
let
res
=
chain_A
.get_residue_ref
(
2
)
.unwrap
();
assert_eq!
(
"SER"
,
res
.name
());
let
res
=
chain_A
.get_residue_ref
(
chain_A
.get_number_residue
())
.unwrap
();
assert_eq!
(
"HSD"
,
res
.name
());
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment