Commit 465dc74f authored by NOEL Philippe's avatar NOEL Philippe

first commit

parents
/target
**/*.rs.bk
Cargo.lock
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CargoProjects">
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pdbparser.iml" filepath="$PROJECT_DIR$/.idea/pdbparser.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/benches" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="64a2b8c5-21c2-4675-aa00-4ee42fda4a9b" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FUSProjectUsageTrigger">
<session id="-508214503">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.0" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="rs" value="3" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Rust" value="3" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="rs" value="51" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Rust" value="51" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/lib.rs" />
<option value="$PROJECT_DIR$/src/pdb/protein.rs" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1747" />
<option name="y" value="25" />
<option name="width" value="1853" />
<option name="height" value="1175" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="pdbparser" type="b2602c69:ProjectViewProjectNode" />
<item name="pdbparser" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="pdbparser" type="b2602c69:ProjectViewProjectNode" />
<item name="pdbparser" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="pdbparser" type="b2602c69:ProjectViewProjectNode" />
<item name="pdbparser" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="pdb" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="pdbparser" type="b2602c69:ProjectViewProjectNode" />
<item name="pdbparser" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="tests" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Cargo Command.Run pdbparser">
<configuration name="Run pdbparser" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package pdbparser --bin pdbparser" />
<option name="nocapture" value="true" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<method v="2" />
</configuration>
<configuration name="Test lib::tests" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package pdbparser --lib tests" />
<option name="nocapture" value="true" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<method v="2" />
</configuration>
<list>
<item itemvalue="Cargo Command.Test lib::tests" />
<item itemvalue="Cargo Command.Run pdbparser" />
</list>
<recent_temporary>
<list>
<item itemvalue="Cargo Command.Run pdbparser" />
<item itemvalue="Cargo Command.Test lib::tests" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="64a2b8c5-21c2-4675-aa00-4ee42fda4a9b" name="Default Changelist" comment="" />
<created>1539962937666</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1539962937666</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="1747" y="25" width="1853" height="1175" extended-state="6" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24958494" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Python Console" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.3291866" />
<window_info anchor="bottom" id="Run" order="2" weight="0.3291866" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Cargo" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" lean-forward="true" selection-start-line="8" selection-end-line="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/pdb/protein.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="522">
<caret line="31" lean-forward="true" selection-start-line="31" selection-end-line="31" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/lib.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="307">
<caret line="62" column="34" selection-start-line="62" selection-start-column="34" selection-end-line="62" selection-end-column="34" />
<folding>
<element signature="e#1947#1948#0" expanded="true" />
<element signature="e#1983#1984#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
[package]
name = "pdbparser"
version = "0.1.0"
authors = ["NOEL Philippe <philippe.noel@inria.fr>"]
edition = "2018"
[[bin]]
name = "pdbparser"
path = "src/main.rs"
[lib]
name = "pdbparser"
path = "src/lib.rs"
[dependencies]
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::process;
mod pdb;
use self::pdb::protein::Protein;
/// Parse the string to return a f32. The `trim` is used to remove
/// /n and spaces.
///
/// # Errors
/// Will return 0.0 if the String cannot be convert and print the error
///
fn parse_float(s: &String) -> f32 {
match s.trim().parse::<f32>() {
Ok(n) => n,
Err(e) => {
println!("{}", e);
0.0
}
}
}
/// Parse the string to return a i64. The `trim` is used to remove
/// /n and spaces.
///
/// # Errors
/// Will return 0 if the String cannot be convert and print the error
///
fn parse_int(s: &String) -> i64 {
match s.trim().parse::<i64>() {
Ok(n) => n,
Err(e) => {
println!("{}", e);
0
}
}
}
pub fn open_pdb_file(f: &str) -> Protein {
let f = match File::open(f) {
Ok(f) => f,
Err(e) => {
println!("Could not open the file \"{}\"\nError: {}", f, e);
process::exit(1);
}
};
let reader = BufReader::new(f);
let mut protein = Protein::new();
for line in reader.lines() {
let l = line.unwrap();
if l.starts_with("HETAM") || l.starts_with("ATOM") {
let _name = &l[12..17].trim().to_string();
let residue_name = &l[17..20].trim().to_string();
let atom_number = parse_int(&l[6..11].to_string());
let residue_number = parse_int(&l[22..26].to_string());
let x = parse_float(&l[30..38].to_string());
let y = parse_float(&l[38..46].to_string());
let z = parse_float(&l[46..54].to_string());
println!("{} {} {} {:?}", residue_name, atom_number, residue_number, [x, y, z]);
protein.add_info(residue_name.clone(), atom_number, residue_number, [x, y, z]);
}
}
protein
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
extern crate pdbparser;
use pdbparser::open_pdb_file;
fn main() {
//let tutu = open_pdb_file("src/tests/f2_adn.pdb");
let _tutu = open_pdb_file("src/tests/hardcore_protein.pdb");
}
#[derive(Debug)]
pub struct Atom<'a> {
name: &'a str,
number: i64,
coord: [f32; 3],
}
impl<'a> Atom<'a> {
pub fn new(name: &str, number: i64, coord: [f32; 3]) -> Atom {
Atom {
name,
number,
coord,
}
}
}
mod atom;
pub mod protein;
mod residue;
use super::residue::Residue;
#[derive(Debug)]
pub struct Protein<'a> {
name: &'a str,
lst_res: Vec<Residue<'a>>,
last_residue: i64, // Le PDB est ordonné dans l'ordre par numéro de résidu donc si le résidu précédent est différent alors c'est un nouveau
}
impl<'a> Protein<'a> {
pub fn new() -> Protein<'a> {
Protein {
name: "",
lst_res: Vec::new(),
last_residue: 0,
}
}
fn set_last_res(&mut self, n: i64) {
self.last_residue = n;
}
pub fn add_info(&mut self, res_name: String, atom_num: i64, res_num: i64, coord: [f32; 3]) {
// Si c'est un atome avec un nouveau residu on le cree sinon on ajoute l'atome au residu
if self.last_residue != res_num {
self.add_residue(res_num, atom_num, coord, res_name);
self.set_last_res(res_num);
} else {
self.update_residue(res_num.clone(), atom_num, coord);
}
}
fn add_residue(&mut self, res_number: i64, atom_number: i64, coord: [f32; 3], res_name: String) {
self.lst_res.push(Residue::new(res_name,"tutu"));
self.lst_res[res_number as usize].add_atom(atom_number, coord);
}
fn update_residue(&mut self, res_number: i64, atom_number: i64, coord: [f32; 3]) {
self.lst_res[res_number as usize].add_atom(atom_number, coord);
}
}
use super::atom::Atom;
#[derive(Debug)]
pub struct Residue<'a> {
name: String,
lst_atom: Vec<Atom<'a>>,
chain: &'a str,
}
impl<'a> Residue<'a> {
pub fn new(name: &'a str, chain: &'a str) -> Residue<'a> {
Residue {
name,
chain,
lst_atom: Vec::new(),
}
}
pub fn add_atom(&mut self, atom_number: i64, coord: [f32; 3]) {
self.lst_atom.push(Atom::new("toto", atom_number, coord));
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment