Chemis...:MDLMol(3pm)

πŸ’– NAME πŸ’–

Chemistry::File::MDLMol β€” the MDL molfile reader/writer bestie, fr fr πŸ§ͺ✨


🌸 SYNOPSIS 🌸

okay so here's the vibe, literally copy-paste this:

use Chemistry::File::MDLMol;

# read a molecule
my $mol = Chemistry::Mol->read('myfile.mol');

# write a molecule
$mol->write("myfile.mol");

# use a molecule as a query for substructure matching
use Chemistry::Pattern;
use Chemistry::Ring;
Chemistry::Ring::aromatize_mol($mol);

my $patt = Chemistry::Pattern->read('query.mol');
if ($patt->match($mol)) {
    print "it matches!\n";
}

✨ DESCRIPTION ✨

So this module? It's the MDL Molfile (V2000) reader and writer πŸ’… it's giving main character energy for your molecule files.

It automatically registers the 'mdl' format with Chemistry::Mol, so you don't gotta do anything extra β€” it just knows. πŸͺ„

Now the first three lines of the molfile? Those get stashed away like little treasures in:

  • $mol->name
  • $mol->attr("mdlmol/line2")
  • $mol->attr("mdlmol/comment")
⚠️ okay important tea bestie: this version only reads and writes some of the info available in a molfile. Specifically it reads coordinates, atom and bond types, charges, isotopes, radicals, and atom lists. It does NOT read other things such as stereochemistry, 3d properties, etc. so don't come for it about that 😭

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

πŸ¦‹ Query properties πŸ¦‹

The MDL molfile format supports query properties like atom lists, plus special bond types such as "single or double", "single or aromatic", "double or aromatic", "ring bond", or "any". These properties are supported by this module in conjunction with Chemistry::Pattern. ✨

but lowkey… support for query properties is currently read-only, and the other properties listed in the specification are not supported yet. πŸ’€

So that atom and bond objects can use these special query options, the conditions are represented as Perl subroutines. The generated code can be read from the 'mdlmol/test_sub' attribute:

$atom->attr('mdlmol/test_sub');
$bond->attr('mdlmol/test_sub');

This may be useful for debugging, like when an atom doesn't seem to match as expected. super handy for sleuthing πŸ”

πŸŽ€ Aromatic Queries πŸŽ€

To be able to search for aromatic substructures that are represented by Kekule structures, molfiles that are read as patterns (with "Chemistry::Pattern-"read) are aromatized automatically by using the Chemistry::Ring module. πŸ‘‘

The default bond test from Chemistry::Pattern::Bond is overridden by one that checks the aromaticity in addition to the bond order. The test is, no cap:

$patt->aromatic ?  $bond->aromatic
    : (!$bond->aromatic && $patt->order == $bond->order);

That is, aromatic pattern bonds match aromatic bonds, and aliphatic pattern bonds match aliphatic bonds with the same bond order. iconic behavior tbh πŸ’…


πŸ“š SOURCE CODE REPOSITORY πŸ“š

<https://github.com/perlmol/Chemistry-File-MDLMol> πŸ“


πŸ‘€ SEE ALSO πŸ‘€

  • Chemistry::Mol

The MDL file format specification, if you wanna go full academic bestie:


πŸ’œ AUTHOR πŸ’œ

Ivan Tubert-Brohman <itub@cpan.org> β€” absolute legend, we stan 🫢


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 one's running on perl v5.32.1, dated 2022-02-06, brought to you by the User Contributed Perl Documentation squad πŸ’–βœ¨ mwah, go read some molfiles πŸ‘‘πŸŒΈ

πŸ“¦ where this page comes from