Skip to content

Commit

Permalink
format due and tables
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli committed Oct 3, 2024
1 parent ee6cbd1 commit feca121
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
21 changes: 14 additions & 7 deletions package/MDAnalysis/due.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,33 @@
"""

__version__ = '0.0.5'
__version__ = "0.0.5"


class InactiveDueCreditCollector(object):
"""Just a stub at the Collector which would not do anything"""

def _donothing(self, *args, **kwargs):
"""Perform no good and no bad"""
pass # pylint: disable=unnecessary-pass
pass # pylint: disable=unnecessary-pass

def dcite(self, *args, **kwargs):
"""If I could cite I would"""

def nondecorating_decorator(func):
return func

return nondecorating_decorator

cite = load = add = _donothing

def __repr__(self):
return self.__class__.__name__ + '()'
return self.__class__.__name__ + "()"


def _donothing_func(*args, **kwargs):
"""Perform no good and no bad"""
pass # pylint: disable=unnecessary-pass
pass # pylint: disable=unnecessary-pass


try:
Expand All @@ -60,17 +63,21 @@ def _donothing_func(*args, **kwargs):
import duecredit

from duecredit import due, BibTeX, Doi, Url
if 'due' in locals() and not hasattr(due, 'cite'):

if "due" in locals() and not hasattr(due, "cite"):
raise RuntimeError(
"Imported due lacks .cite. DueCredit is now disabled")
"Imported due lacks .cite. DueCredit is now disabled"
)
except Exception as err:
if not isinstance(err, ImportError):
import logging
import warnings

errmsg = "Failed to import duecredit due to {}".format(str(err))
warnings.warn(errmsg)
logging.getLogger("duecredit").error(
"Failed to import duecredit due to {}".format(str(err)))
"Failed to import duecredit due to {}".format(str(err))
)
# else:
# Do not issue any warnings if duecredit is not installed;
# this is the user's choice (Issue #1872)
Expand Down
44 changes: 26 additions & 18 deletions package/MDAnalysis/topology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
.. autodata:: TABLE_VDWRADII
"""

from typing import Any

def kv2dict(s, convertor=str):

def kv2dict(s, convertor: Any = str):
"""Primitive ad-hoc parser of a key-value record list.
* The string *s* should contain each key-value pair on a separate
Expand Down Expand Up @@ -172,10 +174,12 @@ def kv2dict(s, convertor=str):
#: with :func:`MDAnalysis.topology.core.guess_atom_type`.
atomelements = kv2dict(TABLE_ATOMELEMENTS)

# fmt: off
elements = ['H',
'LI', 'BE', 'B', 'C', 'N', 'O', 'F',
'NA', 'MG', 'AL', 'P', 'SI', 'S', 'CL',
'K']
# fmt: on

#: Plain-text table with atomic masses in u.
TABLE_MASSES = """
Expand Down Expand Up @@ -376,28 +380,31 @@ def kv2dict(s, convertor=str):
#: .. SeeAlso:: :func:`MDAnalysis.topology.core.guess_bonds`
vdwradii = kv2dict(TABLE_VDWRADII, convertor=float)

Z2SYMB = {1: 'H', 2: 'He',
3: 'Li', 4: 'Be', 5: 'B', 6: 'C', 7: 'N', 8: 'O', 9: 'F', 10: 'Ne',
11: 'Na', 12: 'Mg', 13: 'Al', 14: 'Si', 15: 'P', 16: 'S', 17: 'Cl', 18: 'Ar',
19: 'K', 20: 'Ca', 21: 'Sc', 22: 'Ti', 23: 'V', 24: 'Cr', 25: 'Mn', 26: 'Fe',
27: 'Co', 28: 'Ni', 29: 'Cu', 30: 'Zn', 31: 'Ga', 32: 'Ge', 33: 'As', 34: 'Se',
35: 'Br', 36: 'Kr', 37: 'Rb', 38: 'Sr', 39: 'Y', 40: 'Zr', 41: 'Nb', 42: 'Mo',
43: 'Tc', 44: 'Ru', 45: 'Rh', 46: 'Pd', 47: 'Ag', 48: 'Cd', 49: 'In', 50: 'Sn',
51: 'Sb', 52: 'Te', 53: 'I', 54: 'Xe', 55: 'Cs', 56: 'Ba', 57: 'La', 58: 'Ce',
59: 'Pr', 60: 'Nd', 61: 'Pm', 62: 'Sm', 63: 'Eu', 64: 'Gd', 65: 'Tb', 66: 'Dy',
67: 'Ho', 68: 'Er', 69: 'Tm', 70: 'Yb', 71: 'Lu', 72: 'Hf', 73: 'Ta', 74: 'W',
75: 'Re', 76: 'Os', 77: 'Ir', 78: 'Pt', 79: 'Au', 80: 'Hg', 81: 'Tl', 82: 'Pb',
83: 'Bi', 84: 'Po', 85: 'At', 86: 'Rn', 87: 'Fr', 88: 'Ra', 89: 'Ac', 90: 'Th',
91: 'Pa', 92: 'U', 93: 'Np', 94: 'Pu', 95: 'Am', 96: 'Cm', 97: 'Bk', 98: 'Cf',
99: 'Es', 100: 'Fm', 101: 'Md', 102: 'No', 103: 'Lr', 104: 'Rf', 105: 'Db',
106: 'Sg', 107: 'Bh', 108: 'Hs', 109: 'Mt', 110: 'Ds', 111: 'Rg', 112: 'Cn',
# fmt: off
Z2SYMB = {1: 'H', 2: 'He',
3: 'Li', 4: 'Be', 5: 'B', 6: 'C', 7: 'N', 8: 'O', 9: 'F', 10: 'Ne',
11: 'Na', 12: 'Mg', 13: 'Al', 14: 'Si', 15: 'P', 16: 'S', 17: 'Cl', 18: 'Ar',
19: 'K', 20: 'Ca', 21: 'Sc', 22: 'Ti', 23: 'V', 24: 'Cr', 25: 'Mn', 26: 'Fe',
27: 'Co', 28: 'Ni', 29: 'Cu', 30: 'Zn', 31: 'Ga', 32: 'Ge', 33: 'As', 34: 'Se',
35: 'Br', 36: 'Kr', 37: 'Rb', 38: 'Sr', 39: 'Y', 40: 'Zr', 41: 'Nb', 42: 'Mo',
43: 'Tc', 44: 'Ru', 45: 'Rh', 46: 'Pd', 47: 'Ag', 48: 'Cd', 49: 'In', 50: 'Sn',
51: 'Sb', 52: 'Te', 53: 'I', 54: 'Xe', 55: 'Cs', 56: 'Ba', 57: 'La', 58: 'Ce',
59: 'Pr', 60: 'Nd', 61: 'Pm', 62: 'Sm', 63: 'Eu', 64: 'Gd', 65: 'Tb', 66: 'Dy',
67: 'Ho', 68: 'Er', 69: 'Tm', 70: 'Yb', 71: 'Lu', 72: 'Hf', 73: 'Ta', 74: 'W',
75: 'Re', 76: 'Os', 77: 'Ir', 78: 'Pt', 79: 'Au', 80: 'Hg', 81: 'Tl', 82: 'Pb',
83: 'Bi', 84: 'Po', 85: 'At', 86: 'Rn', 87: 'Fr', 88: 'Ra', 89: 'Ac', 90: 'Th',
91: 'Pa', 92: 'U', 93: 'Np', 94: 'Pu', 95: 'Am', 96: 'Cm', 97: 'Bk', 98: 'Cf',
99: 'Es', 100: 'Fm', 101: 'Md', 102: 'No', 103: 'Lr', 104: 'Rf', 105: 'Db',
106: 'Sg', 107: 'Bh', 108: 'Hs', 109: 'Mt', 110: 'Ds', 111: 'Rg', 112: 'Cn',
113: 'Nh', 114: 'Fl', 115: 'Mc', 116: 'Lv', 117: 'Ts', 118: 'Og'}
# fmt: on

SYMB2Z = {v:k for k, v in Z2SYMB.items()}
SYMB2Z = {v: k for k, v in Z2SYMB.items()}

# Conversion between SYBYL atom types and corresponding elements
# Tripos MOL2 file format:
# https://web.archive.org/web/*/http://chemyang.ccnu.edu.cn/ccb/server/AIMMS/mol2.pdf
# fmt: off
SYBYL2SYMB = {
"H": "H", "H.spc": "H", "H.t3p": "H",
"C.3": "C", "C.2": "C", "C.1": "C", "C.ar": "C", "C.cat": "C",
Expand Down Expand Up @@ -428,4 +435,5 @@ def kv2dict(s, convertor=str):
"Se": "Se",
"Mo": "Mo",
"Sn": "Sn",
}
}
# fmt: on
24 changes: 24 additions & 0 deletions package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,27 @@ Discord = 'https://discord.com/channels/807348386012987462/'
Blog = 'https://www.mdanalysis.org/blog/'
Twitter = 'https://twitter.com/mdanalysis'
Source = 'https://github.com/mdanalysis/mdanalysis'

[tool.setuptools]
# as a zipped egg the *.so files are not found (at
# least in Ubuntu/Linux)
zip-safe = false

[tool.setuptools.packages]
find = {}

[tool.setuptools.package-data]
MDAnalysis = [
'analysis/data/*.npy',
]

[tool.black]
line-length = 79
target-version = ['py310', 'py311', 'py312']
include = '''
(
tables\.py
| due\.py
)
'''
required-version = '24'

0 comments on commit feca121

Please sign in to comment.