Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ addBasicArgs(allParser);

const args = parser.parse_args();

if (!fs.existsSync(args.in)) {
console.error(`Input path "${args.in}" does not exist`);
process.exit(1);
}

if (!fs.existsSync(args.out)) {
fs.mkdirSync(args.out, { recursive: true });
}
Expand All @@ -103,10 +98,28 @@ export function getFileName(inPath: string) {
}

async function main() {
const renderer = new ImageRenderer(args.width, args.height, args.format, args.plddt, new FocusFirstResidue());
// Support multiple, comma-separated files
var files:string[] = args.in.split(',');

// Confirm all files exist
files.forEach(file => {
if (!fs.existsSync(file)) {
console.error(`Input path "${file}" does not exist`);
process.exit(1);
}
});

const fileName = getFileName(args.in);
const cif = await readCifFile(args.in);
// Run the rendering process
files.forEach(async file => {
await renderFile(file);
});
Comment on lines +113 to +115
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
files.forEach(async file => {
await renderFile(file);
});
for (const file in files) {
await renderFile(file);
});

Need a normal loop here so the await does what it's supposed to. What you did would execute all the renders in parallel which you don't really want as this is a single threaded environment and you would also likely run out of memory if the input list was really long.

}

async function renderFile(filePath: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async function renderFile(filePath: string) {
async function renderFile(filePath: string, renderer: ImageRenderer) {

and declare const renderer = new ImageRenderer(args.width, args.height, args.format, args.plddt, new FocusFirstResidue()); in the main function. This will reuse the renderer for all the renders and should work out of the box sinde the render function always calls this.canvas3d.clear(); at the end.

var fileName = getFileName(filePath);

const renderer = new ImageRenderer(args.width, args.height, args.format, args.plddt, new FocusFirstResidue());
const cif = await readCifFile(filePath);
const trajectory = await getTrajectory(cif as CifFrame);

switch (args.render) {
Expand Down