Skip to content

Commit

Permalink
Fix trj conversion error
Browse files Browse the repository at this point in the history
  • Loading branch information
supernova4869 committed Nov 10, 2024
1 parent 8cf0ec3 commit 991bd92
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 210 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "s_mmpbsa"
version = "0.6.5"
version = "0.6.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
26 changes: 12 additions & 14 deletions src/analyzation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ pub fn analyze_controller(result_wt: &SMResult, result_as: &Vec<SMResult>, tempe
println!(" 3 Output binding energy by residue at specific time");
println!(" 4 Output ligand binding energy by atom at specific time");
println!("10 Output residue-wised binding energy by time as default names");
let sel_fun: i32 = get_input_selection();
let sel_fun = get_input_selection();
match sel_fun {
-1 => {
Ok(-1) => {
println!("Input the time point (in ns) to output (default: average):");
let ts_ids = get_time_range(result_wt);
if ts_ids.is_empty() {
Expand All @@ -128,8 +128,8 @@ pub fn analyze_controller(result_wt: &SMResult, result_as: &Vec<SMResult>, tempe
println!("Finished writing pdb file(s) with binding energy information.");
println!("Finished drawing figures with pml file(s) by PyMOL.");
},
0 => exit(0),
1 => {
Ok(0) => exit(0),
Ok(1) => {
println!("Input the time point (in ns) to output (default: average):");
let ts_ids = get_time_range(result_wt);
if ts_ids.is_empty() {
Expand All @@ -140,12 +140,12 @@ pub fn analyze_controller(result_wt: &SMResult, result_as: &Vec<SMResult>, tempe
analyze_summary(result, temperature, wd, &format!("{}-{}", sys_name, result.mutation), &ts_ids)
}
},
2 => {
Ok(2) => {
for result in &results {
analyze_traj(result, wd, &format!("{}-{}", sys_name, result.mutation))
}
},
3 => {
Ok(3) => {
println!("Input the time point (in ns) to output (default: average):");
let ts_ids = get_time_range(result_wt);
if ts_ids.is_empty() {
Expand All @@ -159,18 +159,19 @@ pub fn analyze_controller(result_wt: &SMResult, result_as: &Vec<SMResult>, tempe
}
println!("Finished writing residue-wised binding energy file(s).");
},
4 => {
Ok(4) => {
for result in &results {
analyze_atom(result, wd, &format!("{}-{}", sys_name, result.mutation))
}
println!("Finished writing atom-wised binding energy pdb file(s) for ligand.");
},
10 => {
Ok(10) => {
for result in &results {
output_all_details(result, wd, &format!("{}-{}", sys_name, result.mutation))
}
},
_ => println!("Invalid input")
Ok(_) => {},
Err(_) => {}
}
}
}
Expand Down Expand Up @@ -328,7 +329,7 @@ fn select_res_by_range(results: &SMResult) -> (String, Vec<usize>) {
println!(" 4 Ligand and receptor residues by: CA within a specified distance");
println!(" 5 Self-defined residue range");
// 残基范围确定
let i: i32 = get_input_selection();
let i = get_input_selection().unwrap();
let mut range_des = String::from("4A");
let target_res = match i {
1 => {
Expand Down Expand Up @@ -380,10 +381,7 @@ fn select_res_by_range(results: &SMResult) -> (String, Vec<usize>) {
.map(|&i| results.residues[i].id) // 索引用id
.collect()
},
_ => {
println!("Invalid selection");
vec![]
}
_ => vec![],
};
(range_des, target_res)
}
Expand Down
189 changes: 81 additions & 108 deletions src/fun_para_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,58 @@ use crate::{confirm_file_validity, convert_cur_dir, set_program};
use crate::fun_para_system::{set_para_trj, set_para_trj_pdbqt};
use crate::parse_tpr::TPR;

fn list_basic_progs(settings: &mut Settings) {
println!(" -5 Set number of parallel kernels, current: {}", settings.nkernels);
println!(" -4 Set delphi path, current: {}", match &settings.delphi_path {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -3 Set apbs path, current: {}", match &settings.apbs_path {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -2 Set PBSA kernel, current: {}", match &settings.pbsa_kernel {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -1 Toggle whether debug mode, current: {}", settings.debug_mode);
}

fn set_basic_progs(opt: i32, settings: &mut Settings) {
match opt {
-2 => {
println!("Input PBSA kernel (if empty, means not to do PBSA calculation):");
let s: String = get_input_selection().unwrap();
if s.eq("apbs") || s.eq("delphi") {
settings.pbsa_kernel = Some(s)
} else {
settings.pbsa_kernel = None
}
}
-3 => {
println!("Input APBS path:");
let s: String = get_input_selection().unwrap();
match set_program(&Some(s), "apbs", settings) {
Some(s) => settings.apbs_path = Some(s),
None => settings.apbs_path = None
}
}
-4 => {
println!("Input Delphi path:");
let s: String = get_input_selection().unwrap();
match set_program(&Some(s), "delphi", settings) {
Some(s) => settings.delphi_path = Some(s),
None => settings.delphi_path = None
}
}
-5 => {
println!("Input number of parallel kernels (default: 16):");
settings.nkernels = get_input(16);
}
_ => {}
}
}

pub fn set_para_basic_tpr(tpr_path: &String, wd: &Path, settings: &mut Settings) {
let mut trj = String::new();
let mut ndx = String::new();
Expand All @@ -15,20 +67,7 @@ pub fn set_para_basic_tpr(tpr_path: &String, wd: &Path, settings: &mut Settings)
loop {
println!("\n ************ MM/PB-SA Files ************");
println!("-10 Exit program");
println!(" -5 Set number of parallel kernels, current: {}", settings.nkernels);
println!(" -4 Set delphi path, current: {}", match &settings.delphi_path {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -3 Set apbs path, current: {}", match &settings.apbs_path {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -2 Set PBSA kernel, current: {}", match &settings.pbsa_kernel {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -1 Toggle whether debug mode, current: {}", settings.debug_mode);
list_basic_progs(settings);
println!(" 0 Go to next step");
println!(" 1 Assign trajectory file (xtc or trr), current: {}", match trj.len() {
0 => "undefined",
Expand All @@ -40,37 +79,8 @@ pub fn set_para_basic_tpr(tpr_path: &String, wd: &Path, settings: &mut Settings)
});
let i = get_input_selection();
match i {
-1 => settings.debug_mode = !settings.debug_mode,
-2 => {
println!("Input PBSA kernel (if empty, means not to do PBSA calculation):");
let s: String = get_input_selection();
if s.eq("apbs") || s.eq("delphi") {
settings.pbsa_kernel = Some(s)
} else {
settings.pbsa_kernel = None
}
}
-3 => {
println!("Input APBS path:");
let s: String = get_input_selection();
match set_program(&Some(s), "apbs", settings) {
Some(s) => settings.apbs_path = Some(s),
None => settings.apbs_path = None
}
}
-4 => {
println!("Input Delphi path:");
let s: String = get_input_selection();
match set_program(&Some(s), "delphi", settings) {
Some(s) => settings.delphi_path = Some(s),
None => settings.delphi_path = None
}
}
-5 => {
println!("Input number of parallel kernels (default: 16):");
settings.nkernels = get_input(16);
}
0 => {
Ok(-1) => settings.debug_mode = !settings.debug_mode,
Ok(0) => {
if trj.len() == 0 {
println!("Trajectory file not assigned.");
} else if ndx.len() == 0 {
Expand All @@ -80,7 +90,7 @@ pub fn set_para_basic_tpr(tpr_path: &String, wd: &Path, settings: &mut Settings)
set_para_trj(&trj, &mut tpr, &ndx, &wd, &tpr_path, settings);
}
}
1 => {
Ok(1) => {
println!("Input trajectory file path, default: ?md.xtc (\"?\" means the same directory as tpr):");
trj.clear();
stdin().read_line(&mut trj).expect("Failed while reading trajectory file");
Expand All @@ -90,7 +100,7 @@ pub fn set_para_basic_tpr(tpr_path: &String, wd: &Path, settings: &mut Settings)
trj = convert_cur_dir(&trj, tpr_path);
trj = confirm_file_validity(&mut trj, vec!["xtc", "trr", "pdbqt"], tpr_path);
}
2 => {
Ok(2) => {
println!("Input index file path, default: ?index.ndx (\"?\" means the same directory as tpr):");
println!("Note: if no index file prepared, the default index.ndx will be generated according to tpr.");
ndx.clear();
Expand All @@ -105,8 +115,11 @@ pub fn set_para_basic_tpr(tpr_path: &String, wd: &Path, settings: &mut Settings)
}
ndx = confirm_file_validity(&mut ndx, vec!["ndx", "pdbqt"], tpr_path);
}
-10 => break,
_ => println!("Error input.")
Ok(-10) => break,
Ok(other) => {
set_basic_progs(other, settings);
},
Err(_) => {}
};
}
}
Expand All @@ -123,20 +136,7 @@ pub fn set_para_basic_pdbqt(init_receptor_path: &String, init_ligand_path: &Stri
loop {
println!("\n ************ MM/PB-SA Files ************");
println!("-10 Exit program");
println!(" -5 Set number of parallel kernels, current: {}", settings.nkernels);
println!(" -4 Set delphi path, current: {}", match &settings.delphi_path {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -3 Set apbs path, current: {}", match &settings.apbs_path {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -2 Set PBSA kernel, current: {}", match &settings.pbsa_kernel {
Some(s) => s.to_string(),
None => String::from("Not set")
});
println!(" -1 Toggle whether debug mode, current: {}", settings.debug_mode);
list_basic_progs(settings);
println!(" 0 Go to next step");
println!(" 1 Assign docking receptor file, current: {}", match receptor_path.len() {
0 => "undefined",
Expand All @@ -162,37 +162,7 @@ pub fn set_para_basic_pdbqt(init_receptor_path: &String, init_ligand_path: &Stri
println!(" 9 Set ligand spin multiplicity, current: {}", multiplicity);
let i = get_input_selection();
match i {
-1 => settings.debug_mode = !settings.debug_mode,
-2 => {
println!("Input PBSA kernel (if empty, means not to do PBSA calculation):");
let s: String = get_input_selection();
if s.eq("apbs") || s.eq("delphi") {
settings.pbsa_kernel = Some(s)
} else {
settings.pbsa_kernel = None
}
}
-3 => {
println!("Input APBS path:");
let s: String = get_input_selection();
match set_program(&Some(s), "apbs", settings) {
Some(s) => settings.apbs_path = Some(s),
None => settings.apbs_path = None
}
}
-4 => {
println!("Input Delphi path:");
let s: String = get_input_selection();
match set_program(&Some(s), "delphi", settings) {
Some(s) => settings.delphi_path = Some(s),
None => settings.delphi_path = None
}
}
-5 => {
println!("Input number of parallel kernels (default: 16):");
settings.nkernels = get_input(16);
}
0 => {
Ok(0) => {
if ligand_path.len() == 0 {
println!("Ligand file not assigned.");
} else if receptor_path.len() == 0 {
Expand All @@ -202,7 +172,7 @@ pub fn set_para_basic_pdbqt(init_receptor_path: &String, init_ligand_path: &Stri
set_para_trj_pdbqt(&receptor_path, &ligand_path, &flex_path, &ff, &method, &basis, total_charge, multiplicity, &wd, settings);
}
}
1 => {
Ok(1) => {
println!("Input docking receptor file path, default: ?protein.pdbqt (\"?\" means the same directory as initial input):");
receptor_path.clear();
stdin().read_line(&mut receptor_path).expect("Failed while reading receptor file");
Expand All @@ -212,7 +182,7 @@ pub fn set_para_basic_pdbqt(init_receptor_path: &String, init_ligand_path: &Stri
receptor_path = convert_cur_dir(&receptor_path, &init_receptor_path);
receptor_path = confirm_file_validity(&mut receptor_path, vec!["pdbqt"], &init_receptor_path);
}
2 => {
Ok(2) => {
println!("Input docking ligand file path, default: ?DSDP_out.pdbqt (\"?\" means the same directory as initial input):");
ligand_path.clear();
stdin().read_line(&mut ligand_path).expect("Failed while reading ligand file");
Expand All @@ -222,7 +192,7 @@ pub fn set_para_basic_pdbqt(init_receptor_path: &String, init_ligand_path: &Stri
ligand_path = convert_cur_dir(&ligand_path, &init_receptor_path);
ligand_path = confirm_file_validity(&mut ligand_path, vec!["pdbqt"], &init_receptor_path);
}
3 => {
Ok(3) => {
println!("Input docking flexible residues file path, default: None:");
let mut s = String::new();
stdin().read_line(&mut s).expect("Failed while reading ligand file");
Expand All @@ -234,34 +204,37 @@ pub fn set_para_basic_pdbqt(init_receptor_path: &String, init_ligand_path: &Stri
flex_path = Some(s);
};
}
4 => {
Ok(4) => {
println!("Input force field, default: amber14sb");
ff = get_input("amber14sb".to_string());
}
5 => {
Ok(5) => {
println!("Input ligand atom charge calculation method:");
println!("0: antechamber (quick)");
println!("1: gaussian (accurate)");
settings.chg_m = get_input_selection::<usize>();
settings.chg_m = get_input_selection().unwrap();
}
6 => {
Ok(6) => {
println!("Input calculation method, default: B3LYP");
method = get_input("B3LYP".to_string());
}
7 => {
Ok(7) => {
println!("Input basis, default: def2SVP");
basis = get_input("def2SVP".to_string());
}
8 => {
Ok(8) => {
println!("Input total charge of the ligand, should be integer:");
total_charge = get_input_selection::<i32>();
total_charge = get_input_selection().unwrap();
}
9 => {
Ok(9) => {
println!("Input spin multiplicity of the ligand, should be integer:");
multiplicity = get_input_selection::<usize>();
multiplicity = get_input_selection().unwrap();
}
-10 => break,
_ => println!("Error input.")
Ok(-10) => break,
Ok(other) => {
set_basic_progs(other, settings);
},
Err(_) => {}
};
}
}
Loading

0 comments on commit 991bd92

Please sign in to comment.