Skip to content

Commit 7d035a7

Browse files
committed
Merge branch 'main' of github.com:TravisWheelerLab/mdrepo-rs
2 parents 7793314 + 977c7ed commit 7d035a7

File tree

9 files changed

+100
-71
lines changed

9 files changed

+100
-71
lines changed

Cargo.lock

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libmdrepo/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub const TRAJECTORY_FILE_EXTS: &[&str] = &[
154154
// - .vasp / POSCAR — VASP structure format
155155
// - .config / .cfg — DL_POLY config file
156156
// - .lmp — LAMMPS structure (alternate extension)
157-
pub const STRUCTURE_FILE_EXTS: &[&str] = &["pdb"];
157+
pub const STRUCTURE_FILE_EXTS: &[&str] = &["pdb", "gro"];
158158

159159
// Here are common topology file extensions used in molecular dynamics simulations:
160160
// GROMACS

mdr-db/src/ops.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::schema::*;
77
// ── helpers ───────────────────────────────────────────────────────────────────
88

99
fn limit(n: Option<i64>) -> i64 {
10-
n.unwrap_or(20).min(1000)
10+
n.unwrap_or(200).min(1000)
1111
}
1212

1313
// ── md_contribution ───────────────────────────────────────────────────────────
@@ -1695,7 +1695,10 @@ pub fn list_social_accounts(
16951695
Ok((count, results))
16961696
}
16971697

1698-
pub fn get_social_account(conn: &mut PgConnection, rid: i32) -> QueryResult<SocialAccount> {
1698+
pub fn get_social_account(
1699+
conn: &mut PgConnection,
1700+
rid: i32,
1701+
) -> QueryResult<SocialAccount> {
16991702
socialaccount_socialaccount::table
17001703
.find(rid)
17011704
.select(SocialAccount::as_select())
@@ -1766,7 +1769,10 @@ pub fn get_social_app(conn: &mut PgConnection, rid: i32) -> QueryResult<SocialAp
17661769
.first(conn)
17671770
}
17681771

1769-
pub fn insert_social_app(conn: &mut PgConnection, new: NewSocialApp) -> QueryResult<SocialApp> {
1772+
pub fn insert_social_app(
1773+
conn: &mut PgConnection,
1774+
new: NewSocialApp,
1775+
) -> QueryResult<SocialApp> {
17701776
diesel::insert_into(socialaccount_socialapp::table)
17711777
.values(&new)
17721778
.returning(SocialApp::as_returning())
@@ -1818,7 +1824,10 @@ pub fn list_social_app_sites(
18181824
Ok((count, results))
18191825
}
18201826

1821-
pub fn get_social_app_site(conn: &mut PgConnection, rid: i64) -> QueryResult<SocialAppSite> {
1827+
pub fn get_social_app_site(
1828+
conn: &mut PgConnection,
1829+
rid: i64,
1830+
) -> QueryResult<SocialAppSite> {
18221831
socialaccount_socialapp_sites::table
18231832
.find(rid)
18241833
.select(SocialAppSite::as_select())

mdr-gen-meta/src/main.rs

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,53 @@ fn run(args: Args) -> Result<()> {
9292
let mut trajectory_file_name: Option<String> = None;
9393
let mut structure_file_name: Option<String> = None;
9494
let mut topology_file_name: Option<String> = None;
95-
for up_file in up_files.iter().filter(|f| f.is_primary) {
96-
match up_file.file_type.as_str() {
97-
"Trajectory" => trajectory_file_name = Some(up_file.filename.clone()),
98-
"Structure" => structure_file_name = Some(up_file.filename.clone()),
99-
"Topology" => topology_file_name = Some(up_file.filename.clone()),
100-
_ => additional_files.push(metadata::AdditionalFile {
101-
file_name: up_file.filename.clone(),
102-
file_type: up_file.file_type.clone(),
103-
description: up_file.description.clone(),
104-
}),
95+
96+
for file in up_files {
97+
if file.is_primary {
98+
match file.file_type.as_str() {
99+
"Trajectory" => {
100+
if trajectory_file_name.is_none() {
101+
trajectory_file_name = Some(file.filename.clone())
102+
} else {
103+
bail!("Found multiple primary trajectory files");
104+
}
105+
}
106+
"Structure" => {
107+
if structure_file_name.is_none() {
108+
structure_file_name = Some(file.filename.clone())
109+
} else {
110+
bail!("Found multiple primary structure files");
111+
}
112+
}
113+
"Topology" => {
114+
if topology_file_name.is_none() {
115+
topology_file_name = Some(file.filename.clone())
116+
} else {
117+
bail!("Found multiple primary topology files");
118+
}
119+
}
120+
_ => bail!(
121+
r#"Primary file type "{}" is not Trajectory/Structure/Topology"#,
122+
file.file_type
123+
),
124+
}
125+
} else {
126+
additional_files.push(metadata::AdditionalFile {
127+
file_name: file.filename.clone(),
128+
file_type: file.file_type.clone(),
129+
description: file.description.clone(),
130+
})
105131
}
106132
}
107133

108-
if ![
109-
&trajectory_file_name,
110-
&structure_file_name,
111-
&topology_file_name,
112-
]
113-
.iter()
114-
.all(|val| val.is_some())
115-
{
116-
bail!("Missing one of required files!")
134+
for (field, val) in [
135+
("trajectory_file_name", &trajectory_file_name),
136+
("structure_file_name", &structure_file_name),
137+
("topology_file_name", &topology_file_name),
138+
] {
139+
if val.is_none() {
140+
bail!(r#""{field}" has no value"#)
141+
}
117142
}
118143

119144
let (_, ligands_res) =
@@ -258,6 +283,11 @@ fn run(args: Args) -> Result<()> {
258283
contributors,
259284
};
260285

286+
let errors = meta.check();
287+
if !errors.is_empty() {
288+
bail!("Errors!\n{}", errors.join("\n"));
289+
}
290+
261291
let mut out_file = open_outfile(&args.outfile)?;
262292
let format = args.format.clone().unwrap_or(guess_format(&args.outfile));
263293
write!(

mdr-process/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2024"
77
anyhow = "1.0.100"
88
chksum-md5 = "0.1.0"
99
clap = { version = "4", features = ["derive"] }
10-
dotenv = "0.15.0"
1110
env_logger = "0.11.8"
1211
log = "0.4.29"
1312
multiset = "0.0.5"
@@ -21,6 +20,7 @@ urlencoding = "2.1.3"
2120
validator = { version = "0.20.0", features = ["derive"] }
2221
which = "8.0.0"
2322
libmdrepo = { path = "../libmdrepo" }
23+
dotenvy = "0.15.7"
2424

2525
[dev-dependencies]
2626
assert_cmd = "2.1.2"

mdr-process/src/process.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::types::{
44
UniprotEntry, UniprotResponse,
55
};
66
use anyhow::{anyhow, bail, Result};
7+
use dotenvy::dotenv;
78
use libmdrepo::{
89
common::{file_exists, get_md5, read_file},
910
metadata::{self, Meta},
@@ -24,9 +25,7 @@ use which::which;
2425
// --------------------------------------------------
2526
pub fn process(args: &ProcessArgs) -> Result<()> {
2627
debug!("{args:?}");
27-
28-
// It's OK if there's no .env
29-
let _ = dotenv::dotenv();
28+
dotenv().ok();
3029
let input_dir = path::absolute(&args.dirname)?;
3130
let processed_dir = args
3231
.out_dir
@@ -403,19 +402,6 @@ pub fn sample_trajectory(
403402
Ok(())
404403
}
405404

406-
// --------------------------------------------------
407-
//pub fn db_connection(server: &Server) -> Result<postgres::Client> {
408-
// dotenv().ok();
409-
// let env_key = match server {
410-
// Server::Production => "PRODUCTION_DB_URL",
411-
// Server::Staging => "STAGING_DB_URL",
412-
// };
413-
// dbg!(&env_key);
414-
// let db_url = env::var(env_key).expect(&format!("{env_key} must be set"));
415-
// postgres::Client::connect(&db_url, postgres::NoTls)
416-
// .map_err(|_| anyhow!("Failed db connection"))
417-
//}
418-
419405
// --------------------------------------------------
420406
pub fn make_import_json(
421407
meta_path: &PathBuf,

mdr-process/src/reprocess.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
types::{ProcessArgs, ReprocessArgs},
44
};
55
use anyhow::{bail, Result};
6+
use dotenvy::dotenv;
67
use libmdrepo::{common::file_exists, metadata::Meta};
78
use log::{debug, info};
89
use std::{
@@ -13,24 +14,27 @@ use std::{
1314

1415
// --------------------------------------------------
1516
pub fn reprocess(args: &ReprocessArgs) -> Result<()> {
16-
let _ = dotenv::dotenv();
17+
dotenv().ok();
1718
let simulation_id = args.simulation_id;
1819
let mdrepo_id = format!("MDR{simulation_id:08}");
1920
debug!("Reprocessing simulation ID {mdrepo_id}");
2021

2122
let data_dir = &args.work_dir.join(&mdrepo_id);
2223
if !data_dir.is_dir() {
23-
fs::create_dir_all(&args.work_dir)?;
24+
fs::create_dir_all(&data_dir)?;
2425
}
2526

2627
let server = &args.server;
2728
let irods_dir =
2829
format!("/iplant/home/shared/mdrepo/{server}/release/{mdrepo_id}/original");
2930
let irods_dir = Path::new(&irods_dir);
31+
debug!(r#"irods_dir = "{}""#, irods_dir.display());
3032

31-
let meta_path = data_dir.join("mdrepo-metadata.toml");
32-
let meta = Meta::from_file(&meta_path)?;
33+
let meta_filename = "mdrepo-metadata.toml";
34+
let meta_local_path = data_dir.join(meta_filename);
35+
irods_fetch(&irods_dir.join(meta_filename), &meta_local_path)?;
3336

37+
let meta = Meta::from_file(&meta_local_path)?;
3438
for filename in &[
3539
&meta.trajectory_file_name,
3640
&meta.structure_file_name,
@@ -67,21 +71,26 @@ pub fn reprocess(args: &ReprocessArgs) -> Result<()> {
6771

6872
// --------------------------------------------------
6973
fn irods_fetch(irods_path: &Path, local_path: &PathBuf) -> Result<()> {
70-
if !file_exists(local_path) {
71-
debug!(
72-
r#"Get "{}" -> "{}""#,
73-
irods_path.display(),
74-
local_path.display()
75-
);
76-
let cmd = Command::new("gocmd")
77-
.args([
78-
"get",
79-
irods_path.to_string_lossy().as_ref(),
80-
local_path.to_string_lossy().as_ref(),
81-
])
82-
.output()?;
83-
if !cmd.status.success() {
84-
bail!(str::from_utf8(&cmd.stderr)?.to_string());
74+
debug!(
75+
r#"Get "{}" -> "{}""#,
76+
irods_path.display(),
77+
local_path.display()
78+
);
79+
80+
if file_exists(local_path) {
81+
debug!("Already downloaded");
82+
} else {
83+
let mut cmd = Command::new("gocmd");
84+
cmd.args([
85+
"get",
86+
irods_path.to_string_lossy().as_ref(),
87+
local_path.to_string_lossy().as_ref(),
88+
]);
89+
debug!("Running {cmd:?}");
90+
let output = cmd.output()?;
91+
92+
if !output.status.success() {
93+
bail!(str::from_utf8(&output.stderr)?.to_string());
8594
}
8695
}
8796
Ok(())

mdr-process/src/ticket.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use crate::{
33
types::{ProcessArgs, TicketArgs},
44
};
55
use anyhow::{anyhow, bail, Result};
6+
use dotenvy::dotenv;
67
use log::{debug, info};
78
use std::{env, fs, path::PathBuf, process::Command};
89
use which::which;
910

1011
// --------------------------------------------------
1112
pub fn process(args: &TicketArgs) -> Result<()> {
1213
debug!("{args:?}");
13-
let _ = dotenv::dotenv();
14+
dotenv().ok();
1415
let script_dir = &args.script_dir.clone().unwrap_or(PathBuf::from(
1516
env::var("SCRIPT_DIR").map_err(|e| anyhow!("SCRIPT_DIR: {e}"))?,
1617
));

mdr-process/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ pub struct TicketArgs {
122122
#[command(alias = "re")]
123123
pub struct ReprocessArgs {
124124
/// Simulation ID
125-
#[arg(value_name = "INT")]
125+
#[arg(short, long, value_name = "INT")]
126126
pub simulation_id: u32,
127127

128128
/// Script directory
129-
#[arg(short('S'), long, value_name = "SCRIPTS")]
129+
#[arg(long, value_name = "SCRIPTS")]
130130
pub script_dir: Option<PathBuf>,
131131

132132
// TODO: Think of adding "server" to this path?
@@ -144,7 +144,7 @@ pub struct ReprocessArgs {
144144
pub json_dir: Option<PathBuf>,
145145

146146
/// Server
147-
#[arg(short, long, value_name = "SERVER", default_value = "staging")]
147+
#[arg(short('S'), long, value_name = "SERVER", default_value = "staging")]
148148
pub server: Server,
149149
}
150150

0 commit comments

Comments
 (0)