{"id":893,"date":"2023-02-16T00:00:00","date_gmt":"2023-02-16T05:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=893"},"modified":"2023-02-17T12:54:50","modified_gmt":"2023-02-17T17:54:50","slug":"how-to-convert-between-structural-file-formats-such-as-pdb-mol2-and-sdf","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/how-to-convert-between-structural-file-formats-such-as-pdb-mol2-and-sdf\/","title":{"rendered":"How to convert between structural file formats such as PDB, MOL2, and SDF"},"content":{"rendered":"\n<p>MOL2, PDB, and SDF are all file formats used to represent molecular structures.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>MOL2<\/strong> is a molecular structure file format developed by Tripos Inc. It provides a simple and flexible way to represent molecular structures and associated information, such as atom and bond data, molecular charges, and partial charges.<\/li>\n\n\n\n<li><strong>PDB (Protein Data Bank)<\/strong> is a widely used file format for storing 3D structural information of proteins and nucleic acids. It provides a standard way of representing the atomic coordinates and other information about a molecule, including residue names, chain identifiers, and atom names.<\/li>\n\n\n\n<li><strong>SDF (Structure-Data File)<\/strong> is a widely used file format for representing molecular structures and associated data. It provides a simple and flexible way to store molecular structure information, as well as other information such as chemical properties, 3D coordinates, and various descriptors.<\/li>\n<\/ol>\n\n\n\n<p>These file formats are widely used in the fields of chemistry, biochemistry, and computational biology, and they can be converted with Open Babel library.<\/p>\n\n\n\n<p>Here is an example of Python code using Open Babel to convert between PDB, MOL2, and SDF file formats:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>import pybel\n\ndef convert_format(input_file, output_file, output_format):\n    # Load the input file using Pybel\n    mol = pybel.readfile(input_file.split('.')&#91;-1], input_file).next()\n    \n    # Write the molecule to the desired output format\n    mol.write(output_format, output_file, overwrite=True)\n\n# Example usage:\ninput_file = \"molecule.pdb\"\noutput_file = \"molecule.mol2\"\noutput_format = \"mol2\"\nconvert_format(input_file, output_file, output_format)\n\ninput_file = \"molecule.mol2\"\noutput_file = \"molecule.sdf\"\noutput_format = \"sdf\"\nconvert_format(input_file, output_file, output_format)<\/code><\/code><\/pre>\n\n\n\n<p>This code uses the Pybel module from Open Babel to perform the file format conversions. The <code>convert_format<\/code> function takes in the input file name, the desired output file name, and the desired output format. It then uses the Pybel <code>readfile<\/code> function to load the input file, and the Pybel <code>write<\/code> function to write the molecule to the desired output format.<\/p>\n\n\n\n<p>You can easily modify this code to convert between other file formats supported by Open Babel, such as PDB and SDF, by changing the input file name and format, and the desired output file name and format.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MOL2, PDB, and SDF are all file formats used to represent molecular structures. These file formats are widely used in the fields of chemistry, biochemistry, and computational biology, and they can be converted with Open Babel library. Here is an example of Python code using Open Babel to convert between PDB, MOL2, and SDF file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":905,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203,299],"tags":[305,307,304,137,306],"class_list":["post-893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-science","tag-mol2","tag-open-babel","tag-pdb","tag-python","tag-sdf"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=893"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/893\/revisions"}],"predecessor-version":[{"id":894,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/893\/revisions\/894"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/905"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}