-
Notifications
You must be signed in to change notification settings - Fork 169
Structure of future attributes #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the design constraints are something like this:
It's pretty clear it'll be hard to make this change backwards compatible, so let's plan this for a 2.x branch. It might make sense to think about the recently added |
Some discussion from #227:
I think I'm leaning towards 1 as well since it's the most flexible, but I wanted to consider the alternatives. @ATenderholt any other ideas or suggestions at this point? What do you think about this endeavor in general? |
I have started working on this, for something to discuss: https://github.com/berquist/cclib/compare/cjson...berquist:qcjson?expand=1 Each attribute should eventually have its own Currently, # Static polarizability from **PROPERTIES/.POLARI.
if line.strip() == "Static polarizabilities (au)":
if not hasattr(self, 'polarizabilities'):
self.polarizabilities = []
polarizability = []
self.skip_lines(inputfile, ['d', 'b', 'directions', 'b'])
for _ in range(3):
line = next(inputfile)
# Separate possibly unspaced huge negative polarizability tensor
# element and the left adjacent column from each other.
line = line.replace('-', ' -')
polarizability.append(line.split()[1:])
self.polarizabilities.append(numpy.array(polarizability)) would become # Static polarizability from **PROPERTIES/.POLARI.
if line.strip() == "Static polarizabilities (au)":
if not hasattr(self, 'polarizabilities'):
self.polarizabilities = attributes.polarizabilities()
self.polarizabilities([])
polarizability = []
self.skip_lines(inputfile, ['d', 'b', 'directions', 'b'])
for _ in range(3):
line = next(inputfile)
# Separate possibly unspaced huge negative polarizability tensor
# element and the left adjacent column from each other.
line = line.replace('-', ' -')
polarizability.append(line.split()[1:])
polarizabilities = self.polarizabilities() + [numpy.array(polarizability)]
self.polarizabilities(polarizabilities) This is not good, but I'm still learning about private class methods. I also still need to handle type conversion for "compound" types (like lists of arrays). |
Desired behavior notes:
if not hasattr(self, 'polarizabilities'):
self.polarizabilities = []
polarizability = []
for _ in range(3):
line = next(inputfile)
polarizability.append(line.split()[1:])
self.polarizabilities.append(polarizability) where
assert isinstance(attribute_classes, dict)
assert isinstance(attribute_instances, dict)
for attribute_name, attribute_instance in attribute_instances:
assert isinstance(attribute_name, str)
# The keys of attribute_instances should be a subset of the keys of attribute_classes
assert attribute_name in attribute_classes
if not isinstance(attribute_instance, attribute_classes[attribute_name])):
attribute_instances[attribute_name] = attribute_classes[attribute_name](attribute_instance)
else:
# The constructor already does type checking/conversion if passed an argument.
attribute_instance.typecheck()
|
I have a general implementation of attribute classes, but still need to modify all the parsers. Here are my current thoughts. If each attribute is a If we want to do this dynamically, as we do now, there is some trickery that needs to be done according to https://stackoverflow.com/a/1355444/, but I haven't tested it. |
Can we have a |
Poke for #419 (comment). |
|
This is for discussion of how attributes will be represented in the future. Some relevant starting points are #398 (comment) and #227.
The text was updated successfully, but these errors were encountered: