Skip to content

Commit

Permalink
Change in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sampurna authored and sampurna committed Mar 25, 2024
1 parent 1cad8eb commit 86b4fc4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
48 changes: 38 additions & 10 deletions package/MDAnalysis/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def make_classes():

# The 'GBase' middle man is needed so that a single topologyattr
# patching applies automatically to all groups.

GBase = bases[GroupBase] = _TopologyAttrContainer._subclass(is_group=True)
for cls in groups:
bases[cls] = GBase._subclass(is_group=True)
Expand Down Expand Up @@ -350,12 +351,14 @@ def __new__(cls, *args, **kwargs):
raise TypeError(errmsg) from None
newcls = u._classes[cls] = parent_cls._mix(cls)
return object.__new__(newcls)

#change 1:AttributeError is raised when the the residue size is [[]].
#If we want to change this, will have to put an elif condition

def __getattr__(self, attr):
selfcls = type(self).__name__
selfcls = type(self).__name__ #checking if object type is valid

if attr in _TOPOLOGY_TRANSPLANTS:
topattr, meth, clstype = _TOPOLOGY_TRANSPLANTS[attr]
topattr, meth, clstype = _TOPOLOGY_TRANSPLANTS[attr] #is method a property or not
if isinstance(meth, property):
attrname = attr
attrtype = 'property'
Expand All @@ -381,7 +384,8 @@ def __getattr__(self, attr):
raise NoDataError(err.format(selfcls=selfcls,
attrname=attrname,
topattr=topattr))

##change 3: need to add another elif condition to raise no attribute error

else:
clean = attr.lower().replace('_', '')
err = '{selfcls} has no attribute {attr}. '.format(selfcls=selfcls,
Expand Down Expand Up @@ -550,8 +554,20 @@ class GroupBase(_MutableBase):
"""

def __init__(self, *args):

try:
if len(args) == 1:
empty = [[]]
if args:
ix = []
u = []

raise TypeError("Empty list")


# # list of atoms/res/segs, old init method
# ix = [at.ix for at in args[0]]
# u = args[0][0].universe
elif len(args) == 1:
# list of atoms/res/segs, old init method
ix = [at.ix for at in args[0]]
u = args[0][0].universe
Expand Down Expand Up @@ -588,34 +604,46 @@ def __getitem__(self, item):
# so just return ourselves sliced by the item
if item is None:
raise TypeError('None cannot be used to index a group.')

# elif item == []:
#print("You have given an empty nested list as input")

elif isinstance(item, numbers.Integral):
if self.ix.size ==0:
return self.level.singular([])
#if self.ix.size ==0:
# print("You have given an empty nested list as input")
# self.ix =[]
# return self.level.singular (self.ix,self.universe) # tried or self.level.singular([]) /[]
#print("This is item",item)
return self.level.singular(self.ix[item], self.universe)
else:
if isinstance(item, list) and item: # check for empty list
# hack to make lists into numpy arrays
# important for boolean slicing
#SampurnaM,24-3-24,to fix issue #3089
if not item:#incase of empty list
return [] #return empty list
#if not item:#incase of empty list
#return [] #return empty list

item = np.array(item)
else: ## return empty list for empty list:change 2
item = []
# We specify _derived_class instead of self.__class__ to allow
# subclasses, such as UpdatingAtomGroup, to control the class
# resulting from slicing.
return self._derived_class(self.ix[item], self.universe)

def __getattr__(self, attr):
selfcls = type(self).__name__
## edit 2: Cls is assigned
if attr in _TOPOLOGY_ATTRS:
cls = _TOPOLOGY_ATTRS[attr]
if attr == cls.singular and attr != cls.attrname:
err = ('{selfcls} has no attribute {attr}. '
'Do you mean {plural}?')
raise AttributeError(err.format(selfcls=selfcls, attr=attr,
plural=cls.attrname))
##another condition just for empty list
#elif attr != cls.singular :
#print("Reached the elif condition",cls.singular)

else:
err = 'This Universe does not contain {singular} information'
raise NoDataError(err.format(singular=cls.singular))
Expand Down
5 changes: 3 additions & 2 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,9 @@ def phi_selections(residues, c_name='C', n_name='N', ca_name='CA'):
.. versionadded:: 1.0.0
"""
if residues.size ==0:
u = []

# u = [] # I am not clear yet on how the [[]] selection affects residue parameter,
#i.e. can we check if residues.size ==0 and set []
u = residues[0].universe
prev = u.residues[residues.ix-1] # obv candidates first
rsid = residues.segids
Expand Down

0 comments on commit 86b4fc4

Please sign in to comment.