Skip to content

Commit

Permalink
Merge pull request cclib#1417 from amandadumi/prop_to_attr
Browse files Browse the repository at this point in the history
renaming properties to attributes throughout
  • Loading branch information
amandadumi authored Apr 29, 2024
2 parents d895e30 + bee89aa commit e86a28f
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 227 deletions.
4 changes: 2 additions & 2 deletions cclib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
collection,
combinator,
driver,
properties,
parser_properties,
attributes,
attribute_parsers,
tree,
)
# isort: on
Expand Down
21 changes: 21 additions & 0 deletions cclib/attribute_parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2024, the cclib development team
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.atombasis import atombasis
from cclib.attribute_parsers.atomcharges import atomcharges
from cclib.attribute_parsers.atomcoords import atomcoords
from cclib.attribute_parsers.atommasses import atommasses
from cclib.attribute_parsers.atomnos import atomnos
from cclib.attribute_parsers.base_parser import base_parser
from cclib.attribute_parsers.charge import charge
from cclib.attribute_parsers.data import ccData
from cclib.attribute_parsers.gbasis import gbasis
from cclib.attribute_parsers.mocoeffs import mocoeffs
from cclib.attribute_parsers.mosyms import mosyms
from cclib.attribute_parsers.mult import mult
from cclib.attribute_parsers.natom import natom
from cclib.attribute_parsers.nbasis import nbasis
from cclib.attribute_parsers.nmo import nmo
from cclib.attribute_parsers.scfenergies import scfenergies
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# the terms of the BSD 3-Clause License.
import re

from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
38 changes: 19 additions & 19 deletions cclib/parser_properties/data.py → cclib/attribute_parsers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from collections import namedtuple
from typing import Any, Dict, List, Mapping, Optional

from cclib.attributes.attribute import Attribute, _attributes
from cclib.method import Electrons, orbitals
from cclib.properties.property import Property, _properties

import numpy

Expand Down Expand Up @@ -104,18 +104,18 @@ class ccData:
# 'TBD' - To Be Decided are the key names of attributes which haven't been included in the cjson format

# The name of all attributes can be generated from the dictionary above.
_attrlist = sorted(_properties.keys())
_attrlist = sorted(_attributes.keys())

# Arrays are double precision by default, but these will be integer arrays.
_intarrays = ["atomnos", "coreelectrons", "homos", "optstatus"]

# Propertys that should be lists of arrays (double precision).
# Attributes that should be lists of arrays (double precision).
_listsofarrays = ["mocoeffs", "moenergies", "moments", "polarizabilities", "scfvalues"]

# Propertys that should be dictionaries of arrays (double precision).
# Attributes that should be dictionaries of arrays (double precision).
_dictsofarrays = ["atomcharges", "atomspins"]

# Propertys that should be dictionaries of dictionaries.
# Attributes that should be dictionaries of dictionaries.
_dictsofdicts = ["populations"]

# Possible statuses for optimization steps.
Expand All @@ -138,7 +138,7 @@ def __init__(self, attributes: Mapping[str, Any] = {}) -> None:
attributes - optional dictionary of attributes to load as data
"""

self._parsed_properties = dict()
self._parsed_attributes = dict()

if attributes:
self.setattributes(attributes)
Expand All @@ -148,7 +148,7 @@ def listify(self) -> None:

attrlist = [k for k in self._attrlist if hasattr(self, k)]
for k in attrlist:
v = _properties[k].type
v = _attributes[k].type
if v == numpy.ndarray:
setattr(self, k, getattr(self, k).tolist())
elif v == list and k in self._listsofarrays:
Expand All @@ -171,7 +171,7 @@ def arrayify(self) -> None:

attrlist = [k for k in self._attrlist if hasattr(self, k)]
for k in attrlist:
v = _properties[k].type
v = _attributes[k].type
precision = "d"
if k in self._intarrays:
precision = "i"
Expand Down Expand Up @@ -252,13 +252,13 @@ def typecheck(self) -> None:
# attr.typecheck()

val = getattr(self, attr)
if isinstance(val, _properties[attr].type):
if isinstance(val, _attributes[attr].type):
continue

try:
val = _properties[attr].type(val)
val = _attributes[attr].type(val)
except ValueError:
args = (attr, type(val), _properties[attr].type)
args = (attr, type(val), _attributes[attr].type)
raise TypeError(
f"attribute {args[0]} is {args[1]} instead of {args[2]} and could not be converted"
)
Expand Down Expand Up @@ -370,30 +370,30 @@ def closed_shell(self) -> bool:
return orbitals.Orbitals(self).closed_shell()

def __setattr__(self, name: str, value: Any) -> None:
if name in _properties:
self._parsed_properties[name] = value
if name in _attributes:
self._parsed_attributes[name] = value
else:
super().__setattr__(name, value)

def __getattr__(self, name: str) -> Any:
# If we couldn't find an attribute directly on the class, which, for
# an Property, should actually be a property, then it's not
# an Attribute, should actually be a property, then it's not
# implemented as a property yet and is in our special attribute
# container.
try:
return self._parsed_properties[name]
return self._parsed_attributes[name]
except KeyError:
pass
# raise PropertyError
# raise AttributeError

@property
def aonames(self):
try:
return self._parsed_properties["aonames"]
return self._parsed_attributes["aonames"]
except:
pass
# except KeyError:
# raise PropertyError
# raise AttributeError

# @aonames.setter
# def aonames(self, val):
Expand All @@ -405,7 +405,7 @@ class ccData_optdone_bool(ccData):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
_properties["optdone"] = Property(bool, "done", "optimization")
_attributes["optdone"] = Attribute(bool, "done", "optimization")

def setattributes(self, *args, **kwargs):
invalid = super().setattributes(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser

import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from cclib.parser_properties import utils
from cclib.parser_properties.base_parser import base_parser
from cclib.attribute_parsers import utils
from cclib.attribute_parsers.base_parser import base_parser


class scfenergies(base_parser):
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e86a28f

Please sign in to comment.