Skip to content

Commit

Permalink
Pdbecif correction (#12)
Browse files Browse the repository at this point in the history
* removed weight

* Use None for empty values

* test writing of fragments

* make empty inchi as None

* bumped version

* removed unnecessary quotes
  • Loading branch information
roshkjr authored Apr 12, 2023
1 parent 96d1dec commit 6fa779f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pdbeccdutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.1"
__version__ = "0.7.2"
2 changes: 1 addition & 1 deletion pdbeccdutils/core/bm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def infer_multiple_chem_comp(path_to_cif: str, bm: dict, sanitize: bool = True):
formula=CalcMolFormula(comp.mol),
modified_date="",
pdbx_release_status="",
weight=round(comp.physchem_properties["exactmw"], 3),
weight="",
)
comp = Component(mol.GetMol(), cif_block, properties, descriptors)
reader_result = ccd_reader.CCDReaderResult(
Expand Down
18 changes: 10 additions & 8 deletions pdbeccdutils/core/ccd_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,15 +1135,13 @@ def _add_sw_info_cif(cif_block_copy):
category = "_software."
sw_fields = ["name", "version", "description"]
sw_loop = cif_block_copy.init_loop(category, sw_fields)
sw_loop.add_row(
cif.quote_list(["rdkit", rdkit.__version__, cif.quote("Core functionality.")])
)
sw_loop.add_row(cif.quote_list(["rdkit", rdkit.__version__, "Core functionality."]))
sw_loop.add_row(
cif.quote_list(
[
"pdbeccdutils",
pdbeccdutils.__version__,
cif.quote("Wrapper to provide 2D templates and molecular fragments."),
"Wrapper to provide 2D templates and molecular fragments.",
]
)
)
Expand Down Expand Up @@ -1188,27 +1186,31 @@ def _add_fragments_and_scaffolds_cif(component, cif_block_copy):

for i, scaffold in enumerate(component.scaffolds):
mol = rdkit.Chem.MolFromSmiles(scaffold.smiles)
inchi = rdkit.Chem.MolToInchi(mol)
inchikey = rdkit.Chem.MolToInchiKey(mol)
new_row = [
component.id,
scaffold.name,
f"S{i+1}",
"scaffold",
scaffold.smiles,
rdkit.Chem.MolToInchi(mol),
rdkit.Chem.MolToInchiKey(mol),
inchi if inchi else None,
inchikey if inchikey else None,
]
substructure_loop.add_row(cif.quote_list(new_row))

for j, fragment in enumerate(component.fragments):
mol = rdkit.Chem.MolFromSmiles(fragment.smiles)
inchi = rdkit.Chem.MolToInchi(mol)
inchikey = rdkit.Chem.MolToInchiKey(mol)
new_row = [
component.id,
fragment.name,
f"F{j+1}",
"fragment",
fragment.smiles,
rdkit.Chem.MolToInchi(mol),
rdkit.Chem.MolToInchiKey(mol),
inchi if inchi else None,
inchikey if inchikey else None,
]
substructure_loop.add_row(cif.quote_list(new_row))

Expand Down
42 changes: 42 additions & 0 deletions pdbeccdutils/tests/test_file_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from pdbeccdutils.core import ccd_writer
from pdbeccdutils.core.component import Component
from pdbeccdutils.core.models import ConformerType
from pdbeccdutils.core.fragment_library import FragmentLibrary
from pdbeccdutils.core.exceptions import CCDUtilsError
from gemmi import cif
from rdkit import Chem

Expand Down Expand Up @@ -209,3 +211,43 @@ def test_plain_cif_write(component: Component, tmpdir, rem_hs):
assert component.id == cif_block.name
for c in to_check:
assert c in cif_block.get_mmcif_category_names()

@staticmethod
def test_fragment_writing(component: Component, tmpdir):
path = tmpdir.join(f"{component.id}.cif")
fragment_library = FragmentLibrary()
component.library_search(fragment_library)
ccd_writer.write_molecule(str(path), component)
cif_block = cif.read(str(path)).sole_block()
assert cif_block
assert component.id == cif_block.name
cif_categories = cif_block.get_mmcif_category_names()
if component.fragments:
assert "_pdbe_chem_comp_substructure." in cif_categories
substructure = cif_block.get_mmcif_category("_pdbe_chem_comp_substructure.")
for _, values in substructure.items():
for value in values:
if value is not None:
assert len(value) > 0

@staticmethod
def test_scaffold_writing(component: Component, tmpdir):
path = tmpdir.join(f"{component.id}.cif")
try:
component.get_scaffolds()
ccd_writer.write_molecule(str(path), component)
cif_block = cif.read(str(path)).sole_block()
assert cif_block
assert component.id == cif_block.name
cif_categories = cif_block.get_mmcif_category_names()
if component.scaffolds:
assert "_pdbe_chem_comp_substructure." in cif_categories
substructure = cif_block.get_mmcif_category(
"_pdbe_chem_comp_substructure."
)
for _, values in substructure.items():
for value in values:
if value is not None:
assert len(value) > 0
except CCDUtilsError:
assert True

4 comments on commit 6fa779f

@osmart
Copy link
Contributor

@osmart osmart commented on 6fa779f Apr 12, 2023

Choose a reason for hiding this comment

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

is this to do with #10?

@osmart
Copy link
Contributor

@osmart osmart commented on 6fa779f Apr 12, 2023

Choose a reason for hiding this comment

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

@roshkjr
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is this to do with #10?

Yes.

Apologies for not honoring your contribution. I understand now that I should have made changes from your PR. I am quite new to development in github.

@roshkjr
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You might find reading this

https://www.aleksandrhovhannisyan.com/blog/atomic-git-commits/

useful

Thanks Oliver for the suggestion. I found the link very useful and I will make sure to incorporate the suggestions into practice

Please sign in to comment.