Skip to content
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

Topology update calls #85

Merged
merged 32 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8ef760b
New properties for atom_types, connection_types. Methods for getting …
ahy3nz Mar 14, 2019
c1053c4
connecoin types are unhashable, so can't just make a set of them. ins…
ahy3nz Mar 14, 2019
c0bfef3
Test topology update calls
ahy3nz Mar 14, 2019
b9bc4c4
More documentation for adding connections between sites
ahy3nz Mar 14, 2019
8808d92
Remove print statement
ahy3nz Mar 14, 2019
493a73d
Update testing top organization: change topology, assert no change, u…
ahy3nz Mar 14, 2019
35d1e00
Use more-specific update calls, not update_top
ahy3nz Mar 14, 2019
ec80852
Merge remote-tracking branch 'upstream/master' into top_update_calls
ahy3nz Mar 16, 2019
259dfa9
Merge remote-tracking branch 'upstream/master' into top_update_calls
ahy3nz Mar 20, 2019
beaa8c6
Refactor atomtype nb expression to just expression
ahy3nz Mar 20, 2019
4a6112f
Refactor tests
ahy3nz Mar 20, 2019
34b7a5b
Rename variable
ahy3nz Mar 20, 2019
8946968
Merge remote-tracking branch 'upstream/master' into top_update_calls
ahy3nz Mar 21, 2019
72d818c
Additional functions for bonds, angels, bondtypes, angletypes. Reorde…
ahy3nz Mar 21, 2019
6ab7250
Refactor functionals into expression to follow api of Potential
ahy3nz Mar 21, 2019
fbe8ae8
Tests for atomtypes and updates
ahy3nz Mar 21, 2019
f25ee75
Simplify imports, add tests for bonds and angles with respective updates
ahy3nz Mar 21, 2019
ed2baed
Fix logic in update commands for Nones
ahy3nz Mar 21, 2019
8da8035
Fix logic in update commands for atomtypes
ahy3nz Mar 21, 2019
21540c3
Avoid unnecessary update calls when adding a connection already calls…
ahy3nz Mar 21, 2019
13d205c
Comment out more lines now that we are continuously updating topology…
ahy3nz Mar 21, 2019
5b1320c
Update topolgoy whenever we add sites or connections. Include warning…
ahy3nz Mar 21, 2019
5861c62
More docstrings, get unique sets when finding different expressions, …
ahy3nz Mar 21, 2019
bd0256c
One more assert for 3 angles, 2 atom types
ahy3nz Mar 21, 2019
c6b1a80
Refactor attributes in topology to not use the word list
ahy3nz Mar 22, 2019
6bcc68d
Refactor external converters
ahy3nz Mar 22, 2019
7a31da9
Refactor format converters
ahy3nz Mar 22, 2019
2680000
Refactor tests
ahy3nz Mar 22, 2019
4f81407
Eliminate attributes that are just do list comprehensions upon call
ahy3nz Mar 22, 2019
af31c96
Merge remote-tracking branch 'upstream/master' into top_update_calls
ahy3nz Mar 22, 2019
bb67ac0
Now parse angles from parme strucure, verify units, simplify imports
ahy3nz Mar 22, 2019
9b9e448
Update convet parmed tests for angles now
ahy3nz Mar 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions topology/core/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def __init__(self,
self._connections = list()

def add_connection(self, other_site):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. this could get confusing since site and top have the same method name.

What would be the difference if someone used top.add_connection but the connectionType was just None

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This ties into #86 , but should hopefully be resolved when #98 gets merged

""" Add a connection between sites

Parameters
---------
other_site : top.Site

Notes
-----
This function WILL NOT include ConnectionType information.
If ConnectionType information needs to be passed,
call top.add_connection
"""
self._connections.append(other_site)

@property
Expand Down
45 changes: 45 additions & 0 deletions topology/core/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def __init__(self, name="Topology", box=None):
self._site_list = list()
self._connection_list = list()

self._atom_types = list()
self._connection_types = list()

self._atom_type_functionals = list()
self._connection_type_functionals = list()

def add_site(self, site):
self._site_list.append(site)

Expand All @@ -42,6 +48,22 @@ def box(self, box):
def n_sites(self):
return len(self._site_list)

@property
def atom_types(self):
return self._atom_types

@property
def connection_types(self):
return self._connection_types

@property
def atom_type_functionals(self):
return [atype.nb_function for atype in self.atom_types]

@property
def connection_type_functionals(self):
return [ctype.potential_function for ctype in self.connection_types]
Copy link
Collaborator

Choose a reason for hiding this comment

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

ctype is very close in name to the python standard lib ctypes

might be better to call this contype?


def positions(self):
xyz = np.empty(shape=(self.n_sites, 3)) * u.nm
for i, site in enumerate(self.site_list):
Expand All @@ -63,13 +85,36 @@ def n_connections(self):
def add_connection(self, connection):
self._connection_list.append(connection)

def update_top(self):
""" Update the entire topology's unique types

Notes
-----
Will update: atom_types, connnection_types
"""
self.update_atom_types()
self.update_connection_list()
self.update_connection_types()

def update_atom_types(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine for right now, but I can see this being an issue with a large system and you only change one atom type.

self._atom_types = []
for site in self.site_list:
if site.atom_type not in self._atom_types:
self._atom_types.append(site.atom_type)

def update_connection_list(self):
for site in self.site_list:
for neighbor in site.connections:
temp_connection = Connection(site, neighbor, update=False)
if temp_connection not in self.connection_list:
self.add_connection(Connection(site, neighbor, update=True))

def update_connection_types(self):
self._connection_types = []
for connection in self.connection_list:
if connection.connection_type not in self._connection_types:
self._connection_types.append(connection.connection_type)

def __repr__(self):
descr = list('<')
descr.append(self.name + ' ')
Expand Down
66 changes: 66 additions & 0 deletions topology/tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from topology.core.topology import Topology
from topology.core.site import Site
from topology.core.atom_type import AtomType
from topology.core.connection import Connection
from topology.core.connection_type import ConnectionType
from topology.core.box import Box
from topology.tests.base_test import BaseTest
from topology.testing.utils import allclose
Expand Down Expand Up @@ -56,3 +58,67 @@ def test_positions_dtype(self):
assert top.positions().dtype == float
assert top.positions().units == u.nm
assert isinstance(top.positions(), u.unyt_array)

def test_top_update(self):
top = Topology()
top.update_top()
assert top.n_sites == 0
assert len(top.atom_types) == 0
assert len(top.atom_type_functionals) == 0
assert top.n_connections == 0
assert len(top.connection_types) == 0
assert len(top.connection_type_functionals) == 0

atomtype = AtomType()
site1 = Site(name='site1', atom_type=atomtype)
top.add_site(site1)
site2 = Site(name='site2', atom_type=atomtype)
top.add_site(site2)
assert top.n_sites == 2
assert len(top.atom_types) == 0
assert len(top.atom_type_functionals) == 0
assert top.n_connections == 0
assert len(top.connection_types) == 0
assert len(top.connection_type_functionals) == 0
top.update_atom_types()
assert top.n_sites == 2
assert len(top.atom_types) == 1
assert len(top.atom_type_functionals) == 1
assert top.n_connections == 0
assert len(top.connection_types) == 0
assert len(top.connection_type_functionals) == 0


ctype = ConnectionType()
connection_12 = Connection(site1=site1, site2=site2,
connection_type=ctype)
top.add_connection(connection_12)
assert top.n_sites == 2
assert len(top.atom_types) == 1
assert len(top.atom_type_functionals) == 1
assert top.n_connections == 1
assert len(top.connection_types) == 0
assert len(top.connection_type_functionals) == 0
top.update_connection_types()
assert top.n_sites == 2
assert len(top.atom_types) == 1
assert len(top.atom_type_functionals) == 1
assert top.n_connections == 1
assert len(top.connection_types) == 1
assert len(top.connection_type_functionals) == 1

site1.atom_type = AtomType(nb_function='sigma*epsilon')
assert top.n_sites == 2
assert len(top.atom_types) == 1
assert len(top.atom_type_functionals) == 1
assert top.n_connections == 1
assert len(top.connection_types) == 1
assert len(top.connection_type_functionals) == 1
top.update_atom_types()
assert top.n_sites == 2
assert len(top.atom_types) == 2
assert len(top.atom_type_functionals) == 2
assert top.n_connections == 1
assert len(top.connection_types) == 1
assert len(top.connection_type_functionals) == 1