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

[WIP]Bug fixing attempts for GSoC 2024 #4530

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 40 additions & 5 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,27 +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:
# 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

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
6 changes: 4 additions & 2 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,13 @@ def phi_selections(residues, c_name='C', n_name='N', ca_name='CA'):
list of AtomGroups
4-atom selections in the correct order. If no C' found in the
previous residue (by resid) then corresponding item in the list
is ``None``.
is ``None``.

.. versionadded:: 1.0.0
"""


# 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
Loading