From 8fd7c2a5131f2eaecc31e7f47c36cea3c4551d04 Mon Sep 17 00:00:00 2001
From: Berk Onat <b.onat@warwick.ac.uk>
Date: Tue, 13 Mar 2018 10:57:01 +0000
Subject: [PATCH] Correction for arrays in topology extraction through ParmEd
 in MDDataAccess

---
 .../nomadcore/md_data_access/MDDataAccess.py  | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/common/python/nomadcore/md_data_access/MDDataAccess.py b/common/python/nomadcore/md_data_access/MDDataAccess.py
index 806a692..cde30a7 100644
--- a/common/python/nomadcore/md_data_access/MDDataAccess.py
+++ b/common/python/nomadcore/md_data_access/MDDataAccess.py
@@ -422,6 +422,16 @@ def pmdConvertTopoDict(topoStor, topoPMD):
 
         def atompairids(atom1,atom2):
             return [atom1[0],atom2[0]]
+     
+        def getX(x, attr, attr2=None):
+            try:
+                if attr2 is not None:
+                    xa = getattr(x, attr)
+                    return getX(xa, attr2)
+                else:
+                    return getattr(x, attr)
+            except AttributeError:
+                return None
 
         structure=None
         segmentList = None
@@ -435,14 +445,15 @@ def pmdConvertTopoDict(topoStor, topoPMD):
         # If topo is a PsfFile, the parameter files were not supplied.
         # Hence, we can only extract topo info from Psf class in topo.
         if isinstance(topoPMD, pmd.charmm.CharmmPsfFile):
-            structure = [[x.name, x.type, x.residue.name, 
-                          x.residue._idx, x.residue.segid, 
-                          x.residue.chain, x.altloc, 
-                          x.irotat, x.occupancy, x.bfactor, x.mass, 
-                          x._charge, x.solvent_radius, x.atomic_number, 
-                          x.tree, x.atom_type.name, x.atom_type.epsilon,
-                          x.atom_type.rmin, x.atom_type.epsilon_14,
-                          x.atom_type.rmin_14, x.atom_type.nbfix] for x in topoPMD.atoms]
+            structure = [[getX(x,'name'), getX(x,'type'), getX(x,'residue','name'), 
+                          getX(x,'residue','_idx'), getX(x,'residue','segid'), 
+                          getX(x,'residue','chain'), getX(x,'altloc'), 
+                          getX(x,'irotat'), getX(x,'occupancy'), getX(x,'bfactor'), 
+                          getX(x,'mass'), getX(x,'_charge'), getX(x,'solvent_radius'), 
+                          getX(x,'atomic_number'), getX(x,'tree'), getX(x,'atom_type','name'), 
+                          getX(x,'atom_type','epsilon'), getX(x,'atom_type','rmin'), 
+                          getX(x,'atom_type','epsilon_14'), getX(x,'atom_type','rmin_14'), 
+                          getX(x,'atom_type','nbfix')] for x in topoPMD.atoms]
             chainList = [a[5] for a in structure]
             segmentList = [a[4] for a in structure]
             residList = [a[3] for a in structure]
-- 
GitLab