From 467863027603da0a86adf7e0c42bbc3f4c78976e Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Tue, 1 Oct 2024 11:06:19 -0400 Subject: [PATCH] Incorrect coordinates from PubChem * Fixed bug where the coordinates from PubChem were accidentally the 2-D rather than 3-D coordinates. --- HISTORY.rst | 4 ++++ molsystem/pubchem.py | 3 ++- tests/test_pubchem.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 2b48e44e..ca90ed8d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,10 @@ ======= History ======= +2024.10.1 -- Bugfix: Incorrect coordinates from PubChem + * Fixed bug where the coordinates from PubChem were accidentally the 2-D rather than + 3-D coordinates. + 2024.8.17 -- Bugfix: current configuration not updated properly * Existing instances of systems did not correctly update when the default configuration was changed. This is release fixes the problem. diff --git a/molsystem/pubchem.py b/molsystem/pubchem.py index 2a9514cd..ae93be43 100644 --- a/molsystem/pubchem.py +++ b/molsystem/pubchem.py @@ -115,7 +115,8 @@ def PC_from_identifier(self, identifier, namespace="detect", fallback=None): for namespace in namespaces: response = requests.get( - f"{pug_url}/compound/{namespace}/{url_quote(identifier)}/SDF" + f"{pug_url}/compound/{namespace}/{url_quote(identifier)}/" + "SDF?record_type=3d" ) if response.status_code == 200: self.from_sdf_text(response.text) diff --git a/tests/test_pubchem.py b/tests/test_pubchem.py index 8fc55f06..b76af298 100644 --- a/tests/test_pubchem.py +++ b/tests/test_pubchem.py @@ -50,3 +50,37 @@ def test_from_name(configuration): if name != correct: print(name) assert name == correct + + +def test_coordinates_from_name(configuration): + """Get the system from a name""" + correct = [ + [0.0, 0.0, 0.0], + [-0.4417, 0.2906, 0.8711], + [0.7256, 0.6896, -0.1907], + [0.4875, -0.8701, 0.2089], + ] + + configuration.PC_from_identifier("ammonia") + + coordinates = configuration.coordinates + if coordinates != correct: + print(coordinates) + assert coordinates == correct + + +def test_coordinates_from_smiles(configuration): + """Get the system from SMILES""" + correct = [ + [0.0, 0.0, 0.0], + [-0.4417, 0.2906, 0.8711], + [0.7256, 0.6896, -0.1907], + [0.4875, -0.8701, 0.2089], + ] + + configuration.PC_from_identifier("N", namespace="smiles") + + coordinates = configuration.coordinates + if coordinates != correct: + print(coordinates) + assert coordinates == correct