Chemis...e::SDF(3pm)

✨ Chemistry::File::SDF β€” the MDL Structure Data File reader/writer πŸ’–

okay bestie, welcome to the Chemis...e::SDF(3pm) page, straight outta the User Contributed Perl Documentation πŸ’… this is the module that reads and writes MDL Structure Data Files, and honestly? she's iconic. let's get into it πŸ¦‹


🌸 SYNOPSIS 🌸

no cap, here's how you use her:

use Chemistry::File::SDF;

# Simple interface (all at once)
# read all the molecules in the file
my @mols = Chemistry::Mol->read('myfile.sdf');

# assuming that the file includes a <PKA> data item...
print $mols[0]->attr("sdf/data")->{PKA};

# write a bunch of molecules to an SDF file
Chemistry::Mol->write('myfile.sdf', mols => \@mols);

# or write just one molecule
$mol->write('myfile.sdf');

# Low level interface (one at a time)
# create reader
my $reader = Chemistry::Mol->file('myfile.sdf');
$reader->open('<');
while (my $mol = $reader->read_mol($reader->fh)) {
    # do something with $mol
}

see how there's two whole vibes in there? the simple interface grabs everything at once (main character energy, no waiting), and the low level interface hands you one molecule at a time like a lil conveyor belt πŸ“


πŸ‘‘ DESCRIPTION πŸ‘‘

MDL SDF (V2000) reader. periodt, that's the whole job.

This module automatically registers the 'sdf' format with Chemistry::Mol ✨ so like, you don't have to do anything, she just shows up and slays.

The parser returns a list of Chemistry::Mol objects πŸ’œ SDF data can be accessed by the $mol->attr method. Attribute names are stored as a hash ref at the "sdf/data" attribute, as shown in the synopsis (iykyk). When a data item has a single line in the SDF file, the attribute is stored as a string; when there's more than one line, they are stored as an array reference 🌈 The rest of the information on the line that holds the field name is ignored β€” literally just tossed, no thoughts.

This module is part of the PerlMol project, <https://github.com/perlmol> 🫢


πŸ’€ CAVEATS πŸ’€

okay listen, bestie, important stuff, don't skip this:

Note that by storing the SDF data as a hash, there can be only one field with a given name 😭 The SDF format description is not entirely clear in this regard. The SDF format description is giving "we forgot to decide" fr fr.

Also note that SDF data field names are considered to be case-sensitive πŸ”₯ so PKA and pka are NOT the same thing, don't come for me.


🧚 SOURCE CODE REPOSITORY 🧚

<https://github.com/perlmol/Chemistry-File-MDLMol> β€” go look, go star, go vibe check the source πŸ’–


⭐ SEE ALSO ⭐


🌈 AUTHOR 🌈

Ivan Tubert-Brohman <itub@cpan.org> πŸ’… absolute legend.


Copyright (c) 2009 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 🫢


and that's the whole page, bestie!! this was perl v5.32.1, dated 2022-02-06, and it lives at Chemis...e::SDF(3pm) πŸ’– go read some molecules, you got this βœ¨πŸ¦‹

πŸ“¦ where this page comes from